Archive

Archive for November, 2016

Popular design news of the week: November 21, 2016 – November 27, 2016

November 27th, 2016 No comments

Every week users submit a lot of interesting stuff on our sister site Webdesigner News, highlighting great content from around the web that can be of interest to web designers.

The best way to keep track of all the great stories and news being posted is simply to check out the Webdesigner News site, however, in case you missed some here’s a quick and useful compilation of the most popular designer news that we curated from the past week.

Note that this is only a very small selection of the links that were posted, so don’t miss out and subscribe to our newsletter and follow the site daily for all the news.

If CSS is so Easy Why Does Everyone Suck?

10 Best New Web Design Tools for November

Site Design: Apple Newsroom

Learn X in Y Minutes

The Coming Revolution in Email Design

Responsive Web Design Basics

Use the Simplest Tools

Your Ultimate Guide to CSS Units

Website of the Year 2016

Google’s Redesigned Google Sites Goes live

10 Bold Rebrands that Made a Big Difference

Sketch 41.1

What’s New in Node 6?

LogoMiner – Catalog of Logo Designs for Analysis and Free Download

Site Design: Anonymoushamburger.com

The Importance of Storytelling in Design

Unbox the Web

Mailchimp Paper Buddy

The Problem Isn’t the Client. It’s You

Introducing Color Fonts

Firefox Focus

6 Experts Predict Top Web & Mobile App Design Trends 2017

5 Things I Learnt as a Designer at LEGO

Daily Curated Color Inspiration

Duco – An App that Helps You Run Successful Design Sprints

Want more? No problem! Keep track of top design news from around the web with Webdesigner News.

LAST DAY: Bundle of 265 High Quality Vector Textures – only $24!

Source

Categories: Designing, Others Tags:

Comics of the week #367

November 26th, 2016 No comments

Every week we feature a set of comics created exclusively for WDD.

The content revolves around web design, blogging and funny situations that we encounter in our daily lives as designers.

These great cartoons are created by Jerry King, an award-winning cartoonist who’s one of the most published, prolific and versatile cartoonists in the world today.

So for a few moments, take a break from your daily routine, have a laugh and enjoy these funny cartoons.

Feel free to leave your comments and suggestions below as well as any related stories of your own…

Messy designer

Untech savvy

Cloned designer

Can you relate to these situations? Please share your funny stories and comments below…

8 Fresh Script Fonts from Rabbittype – only $12!

Source

Categories: Designing, Others Tags:

How To Draw A Diamond Heart Icon in Illustrator

November 25th, 2016 No comments
dansky_diamond-heart-icon-in-adobe-illustrator

In this tutorial, we’re going to learn how to draw a diamond heart icon in Adobe Illustrator.

Download Adobe Illustrator.

Read More at How To Draw A Diamond Heart Icon in Illustrator

Categories: Designing, Others Tags:

Deal: 52% off Professional, Product Screenshots App, Smartmockups

November 25th, 2016 No comments

Need a product screenshot fast? Now you can whip one up faster than it takes Photoshop to warm-up, with the awesome Smartmockup App.

Available for MacOS, Windows, and Linux, this simple tool enables you to preview your artwork in 300+ mockups and then export. So we’re delighted that our sister-site MightyDeals.com has arranged an amazing 52% discount on it—an incredible dollar-saving deal, on any day of the year.

Smartmockups App works just like mockups that use smart objects in Photoshop, simply insert your artwork and the app will insert it in a variety of different mockups for you. There are screen mockups, including desktops, laptops, smartphones, TVs, and even watches; and there are print mockups including business cards, stationery, posters, signs, and flyers. You can change background colors to fit your design, add gradients, or even blur screens to create a depth of field effect.

There are currently over 330 different mockups, but that’s not all! The team behind Smartmockup App are working on fresh mockups, and you’ll get those too, as free updates for life.

The regular retail price for this incredible tool is $29, but for a limited time you can grab it for just $14, that’s 52% off! Head over to MightyDeals.com to start making professional, product screenshots today.

20 Royalty-Free Epic Cinematic Action Music Tracks – only $29!

Source

Categories: Designing, Others Tags:

Random Interesting Facts on HTML/SVG usage

November 25th, 2016 No comments

Last time, we saw how the average web page looks like using data from about 8 million websites. That’s a lot of data, and we’ve been continuing to sift through it. We’re back again this time to showcase some random and hopefully interesting facts on markup usage.

Hiding DOM elements

There are various ways of hiding DOM elements: completely, semantically, or visually.

Considering the current practices and recommendations, check out the findings on the most used methods to hide things via HTML or CSS:

Selector Count
[aria-hidden] 2,609,973
.hidden 1,556,017
.hide 1,389,540
.sr-only 583,126
.visually-hidden 136,635
.visuallyhidden 116,269
.invisible 113,473
[hidden] 31,290

no-js HTML class

When JavaScript libraries like Modernizr run, the no-js class is removed and it’s replaced with js. This way you can apply different CSS rules depending on whether JavaScript is enabled or not in your browser.

We found a total number of 844,242 elements whose HTML class list contains the no-js string. More than 92% of them are html elements.

If you’re wondering about the remaining 8%, check out the top 10:

Element Count
html 782,613
body 31,256
a 17,833
div 7,364
meta 1,104
ul 905
li 789
nav 768
span 431
article 263

noscript

The HTML noscript element defines a section of markup that acts as an alternate content for users that have client-side scripting disabled, or whose browser lacks support. The client-side scripting language is usually JavaScript.

We found 3,536,247 noscript elements within the 8 million top twenty Google results.

AMP

Accelerated Mobile Pages (AMP) is a Google initiative which aims to speed up the mobile web. Most publishers are making their content available in parallel in the AMP format.

To let Google and other platforms know about it, you need to link the AMP and non-AMP pages together.

Within the 8 million pages we looked at, we found only 1,944 non-AMP pages referencing their AMP version using rel=amphtml.

Links attributes & values

href=”javascript:void(0)

We found 2,002,716 a elements with href="javascript:void(0)". Whether you’re coding a button or coding a link, you’re doing it wrong.

href=”javascript:void(0)”
(a) You’re coding a button with the wrong element
(b) You’re coding a link with the wrong technology
Heydon Pickering

target=_blank w/ or w/o rel=noopener

43,924,869 of the anchors we analyzed are using target="_blank" without a rel="noopener" conjunction. In this case, if rel="noopener" is missing, you are leaving your users open to a phishing attack and it’s considered a security vulnerability.

Anchor/Link Count
[target=_blank] 43,924,869
[rel=noopener] 40,756
[target=_blank][rel=noopener] 35,604

MDN:

When using target you should consider adding rel=”noopener noreferrer” to avoid exploitation of the window.opener API.

Ben Halpern and Mathias Bynens also wrote some good articles on this matter and the common advice is: don’t use target=_blank, unless you have good reasons.

href=#top

It seems it is a common practice to use #top as a href value to redirect the user to the top section of the current page. There were found 377,486 a elements with href=#top values.

lang

Léonie Watson:

The HTML lang attribute is used to identify the language of text content on the web. This information helps search engines return language specific results, and it is also used by screen readers that switch language profiles to provide the correct accent and pronunciation.

Of the 8,021,323 pages that we were able to look into, 5,368,133 use the lang attribute on the html element. That’s about 70%!

div

The average web page has around 71 divs. This number was computed after counting all the div elements (576,067,185) encountered within 8,021,323 million pages.

header vs footer

2,358,071 of pages use the header element while the footer is used by 2,363,665 pages. Also we found that only 2,117,448 of pages are using both header and footer.

Element Count
footer 2,363,665
header 2,358,071

Links are not buttons

Neither are div‘s and span‘s.

Element Attribute & Value Count
a class=btn 3,251,114
a class=button 2,776,660
span class=button 292,168
div class=button 278,996
span class=btn 202,054
div class=btn 131,950

In exchange, here are the native buttons statistics:

Selector Count
button 4,237,743
input[type=image] 1,030,802
input[type=button] 916,268

Buttons without a specified type

Speaking of buttons, the button element has a default type of submit. Make sure you always specify the button type, because we found around 1,336,990 button elements with missing type attribute. That’s around 31.5% from the total of buttons found in the wild.

BEM syntax

If you’re a CSS addict, you may have heard about BEM, which is a popular naming convention for HTML classes.

Knowing the BEM naming style that consists of strings containing double-underscores or/and double-dashes, we were able to guess that only 20,463 elements use the BEM naming style.

Bootstrap & Font Awesome

Apparently, we found only 1,711 pages that link to CSS or JavaScript resources that contain the bootstrap[.min.].js|.css. Also, it looks like 379 pages link to CSS resources that contain the font-awesome[.min.].css.

I would have expected more.

WordPress

1,866,241 pages, from the total that we analyzed, contain . We can only assume there are more that use WordPress, but some chose to remove this meta info from their sources.

.clearfix VS .clear VS .cf

There are many naming styles for this well-known CSS utility that help clearing the floats. Here’s the breakdown:

Selector Count
.clearfix 19,573,521
.clear 10,925,887
.cf 1,102,698

Favicon

Modern browsers fetch /favicon.ico automatically and asynchronously. So don’t manually specify its root location, just place it in there. Unless, for some reasons you prefer a different location for it.

It looks like 354,024 publishers still link the /favicon.ico in the head.

Void elements

To close or not to close the void elements, that is the question. Although fine with HTML either way, it is recommended to not close the void elements. At least for the sake of brevity.

Element Count
121,463,561

67,595,285
61,746,984
46,688,572

34,492,680
27,845,389
17,844,667
15,133,457
11,740,839
7,231,827


2,610,890


1,690,891
1,390,339

1,336,974

1,025,183
698,611
435,877
389,717
304,954
286,380
237,606

151,757

145,434
105,688
77,922
56,610
376
310
1

tabindex

On hijacking the tab order, when using tabindex to solve some disconnected UI elements, usually that only pushes the issue up to the document level.

The common advice is to use it with caution. We did notice that 552,109 HTML elements are using the tabindex attribute to override the defaults when navigating with a keyboard.

Missing alt for images

This eternal SEO and accessibility issue still seems to be pretty common after analyzing this set of data. From the total of 139,308,228 images, almost half are missing the alt attribute or use it with a blank value.

Element Count
img 139,308,228
img alt="*" 73,430,818
img alt="" 32,603,650
img w/ missing alt 33,273,760

Custom elements

Excluding the Web Component tags, here is a list of made up tags or custom elements, different to MDN’s HTML element reference.

Element Count
808,253
273,166
111,806
76,501
53,026
51,604
42,703
34,167
33,424
27,451

We did find 21,403 h7 elements too.

A11Y

First rule of ARIA use:

If you can use a native HTML element [HTML51] or attribute with the semantics and behaviour you require already built in, instead of re-purposing an element and adding an ARIA role, state or property to make it accessible, then do so.

Landmark roles

ARIA Landmark Roles help users using assistive technology devices to navigate your site.

You might have seen this warning message when validating a document: “The banner role is unnecessary for element header”. This happens because browsers like iOS Safari do not currently support the above implicit mappings and for now it’s a good practice to keep adding these landmark roles and avoid the HTML validation warnings.

Regarding the HTML5 implicit mappings, here’s the stats:

Element Count

1,144,750

675,970

613,454
236,484

129,845

105,627

4,326

autoplay

Video and audio autoplay is considered a bad practice, not only for accessibility, but also for usability.

So, don’t auto-play and it will please all of your users.

Check out below the findings from the total of 108,321 video and 64,212 audio elements.

Element Count
31,653
5,601
2,595
339
79
22

maximum-scale

Maximum-scale define maximum zoom and when set like maximum-scale=1 it won’t allow the users to zoom your page. You shouldn’t do that, since zooming is an important accessibility feature that is used by a lot of people because it provides a better experience by meeting users’ needs.

Warning from HTML 5.2 Editor’s Draft, 4 October 2016:

Authors should not suppress or limit the ability of users to resize a document, as this causes accessibility and usability issues.

However, we did find 1,047,294 websites using maximum-scale=1 and 87,169 websites with a user-scalable=no value set. At the same time, 326,658 pages are using both maximum-scale=1 and user-scalable=no.

role=button

Setting role=button for a button is allowed but not recommended as the button already has role=button as default implicit ARIA semantic. Still, we did find 26,360 button elements having set a role=button.

Here’s a breakdown on other notable elements, whose behavior was overridden by role=button:

Element Count
577,905

85,565
21,466
8,286

On making clickable things correctly, MDN sums it up:

Be careful when marking up links with the button role. Buttons are expected to be triggered using the Space key, while links are expected to be triggered using the Enter key. In other words, when links are used to behave like buttons, adding role=”button” alone is not sufficient. It will also be necessary to add a key event handler that listens for the Space key in order to be consistent with native buttons.

SVG

There are several ways of including SVG in HTML, we sum them up and found a total of 5,610,764 SVG references.

How to use SVG %
Inline SVG code within HTML 97.05%
Using SVG as an 2.88%
Using SVG as an 0.05%
Using SVG as an 0.02%
Using SVG as an

The object, iframe and embed methods usage is under 1%.

data-*=svg

There are 17,920 elements whose data-* attribute value contains the string svg. Most of the elements are or .

Top 5 data-* values:

  1. http://www.w3.org/2000/svg – 471
  2. hg-svg – 127
  3. svg-siteline-facebook – 114
  4. icon-facebook.svg – 95
  5. twitter.svg – 95

id*=svg

There are 141,813 elements whose id attribute value contains the string “svg”. Most of the elements are or its inner elements.

Top 5 id values:

  1. emotion-header-title-svg – 16,281
  2. cicLeftBtnSVG – 5,793
  3. cicPauseBtnSVG – 5,793
  4. cicPlayBtnSVG – 5,793
  5. cicRightBtnSVG – 5,793

class*=svg

There are 329,004 elements whose class attribute value contains the string “svg”. Most of the elements are , , or inner elements.

Top 10 class values:

  1. sqs-svg-icon--social – 58,501
  2. nav_svg – 29,826
  3. svg – 28,604
  4. mk-svg-icon – 24,193
  5. svg-icon – 12,255
  6. icon_svg – 7,956
  7. ico ico-svg ico-40-svg – 3,980
  8. svg temp_no_id temp_no_img_src – 3,794
  9. svgIcon-use – 3,127
  10. svg temp_no_img_src – 3,017

Regarding the above top, maybe it’s worth mentioning that sqs-svg-icon--social is a (BEM-like) naming convention used by Squarespace website templates.

currentColor

There are 868,194 SVG inner elements that contain the value currentColor, mainly for the fill or stroke attributes.

Top 10 SVG elements

  1. – 845,626
  2. – 12,834
  3. – 6,073
  4. – 3,207
  5. – 1,885
  6. – 1,061
  7. – 575
  8. – 480
  9. – 412
  10. – 206

SVG as background-image (The journey!)

To figure out if an element used SVG for a background-image, things were more complicated. Most of our data only used the HTML documents, but we worked out a solution to get the active stylesheets.

From the total of 6,359,031 domains we were able to gather data from, 84.5% (5,371,806) are using HTML elements with CSS background images, whilst only 1.2% (82,008) domains were using at least one SVG background image.

Also, from the total of 92,388,615 HTML elements with CSS background images, 0.5% (439,447) of them are using a SVG background image.

The process

We went through all of the HTML files and transformed local/relative CSS file references into absolute ones, e.g. became .

This took some time, since we sampled a couple of the results from our first runs, found inconsistencies with the results and had to restart the process. With a zipped file size of 65GB (and unzipped 323GB), it wasn’t a surprise why processing needed a couple of days to produce the above set of results.

Trying and aborting PhantomJS

Since background images can be applied via CSS, we needed something to render the DOM and apply styles to it. We thought of a tool we were very familiar with: PhantomJS. We ran a couple of tests with actual pages and saw that everything seemed to work properly. We then built our Java client to interface with the PhantomJS webserver: starting, opening pages, extracting output, handling responses, saving results and then cleaning up, but ran into disastrous performance results when trying to use and scale the rendering process on even one machine.

Rendering one HTML file would take anything from a couple of seconds to a couple of minutes and we had no way of knowing what PhantomJS was doing. This, coupled with the fact that the resources usage goes up exponentially the larger the DOM is, caused us to ditch it and look for alternatives.

Better luck with Selenium

As luck would have it, a colleague was experimenting with Selenium on top of headless Chrome. Since he had encouraging results in all areas where PhantomJS was lacking, we thought about leaving the Java-do-it-all comfort zone and delegating stuff to other tools if needed. The test results were very promising – headless Chrome looked like it suited our needs marvelously: super fast startup time, great rendering time, and full control over stopping a process.

The Selenium web driver would actually close the binary, as opposed to us sending an exit command to PhantomJS and hoping it wasn’t in 100% load so it would actually process it. This allowed us to control each process individually, without having to use killall every couple of minutes and stopping all processes in case just one of them went rogue and throttled the CPU.

The only problem with this approach was that the JavaScript could no longer be contained in a single, standalone JS file we’d pass onto the PhantomJS executable, but had to be included inline in the actual HTML files. Here’s a simplified version of the script we used, relying on the Window.getComputedStyle() method:

let backgroundImages = [],
    allElem = document.querySelectorAll("*"),
    allElemLength = allElem.length;

for (let i = 0; i < allElemLength; i++) {
  let style = window.getComputedStyle(allElem[i], false),
  backgroundImage = style.backgroundImage.slice(4, -1);
  backgroundImages.push(backgroundImage);
}

Saving data would be done by calling a simple PHP script. We ran a couple of larger-scale tests to validate our choice and everything performed flawlessly, so we went on with setting up a scalable environment.

We processed all HTML files (again) and injected the above JavaScript snippet. The next challenge was uploading everything to Amazon. S3Browser, which we use for “casual” listing and downloading/uploading, didn’t seem fast enough for this job (not the free version, at least). So, we looked for an alternative and came across s3-parallel-put.

We set it up on a local Linux machine, moved over the SSD and had 65GB worth of zipped text data uploaded in no time. It crippled our machine and the local Jenkins server that was running on it – until we upgraded the old Q9550 CPU :).

The problems showed up when starting to scale up. We saw that our single web server would become overwhelmed and stop saving results, even though the Selenium driver was reporting the page had rendered successfully. This also meant many of our queue messages would be wasted (consumed and deleted from the queue), without producing any results.

We thus decided to have a more scrutinized system for keeping track of processed/unprocessed files by using Redis: each time we’d start processing a file, we’d insert the domain name into a Redis set. Each time we’d process a file (our PHP script would be called), we’d insert the domain name into another Redis set. The point was to keep the difference between the two to a minimum (anything over a certain value would mean something wasn’t working properly) and to make retrying easy if it was ever going to be needed.

Hardware setup

For our hardware setup, we started by running 10 threads * 1 Chrome instance each on 10 Amazon c4.large machines, served by one Apache webserver running on a m3.medium initially doing a very lousy job. After toying with Apache’s settings, we scaled everything up gradually and got to 40 c4.large machines being served by Apache webservers running on 4 m3.medium machines behind a load balancer. Our Redis instance was serving all 10 threads * 40 machines * 3-4 requests per 5-20 seconds off a r3.large machine. So, that’s about 60-320 requests per second.

On costs, it’s pretty hard to give a total amount of money spent or CPU-time, since we ran into many issues before having a fully functional and stable ecosystem. Ideally, a single machine would need about 45 seconds for processing 100 files: downloading, unzipping, rendering and cleaning up.

Q&A / Follow up

Why so many tbody elements?

For the above new data, we did perform another full scan for the 8 million documents and also fixed a parsing sanitization issue where the jsoup parser was adding the tbody element automatically for all the tables. This is the answer to the question asked by some of you in the comments: “Why so many tbody elements?”.

As a consequence, the number of elements used on the most pages is now 25, tbody stats being now lessened.

body at 99%?

A little refresher: according to the specifications, omitting the body is fine: Start tag: optional, End tag: optional.

So, one of the most surprising results number, based on your comments, was the missing 1% of body elements. I guess I owe you an answer, for that I went a bit further and ran the parser again to get some insights:

  • As some of you already guessed, most of the pages are missing the body tag due to the high frameset usage.
  • The client-side redirect method using meta http-equiv="refresh", followed by no body content is another reason.
  • Pretty disappointing to see that, among the pages expected to rank high on Google, there are lots of them that use the rough JavaScript window.location solution in order to redirect people to other domains. Again, these kinds of pages are not including the body section at all.
  • Some of the pages marked with missing body were completely broken due to PHP errors for example. Some were omitting the starting body tag but not the end tag.

Want more?

Have an element/attribute you’d want to see the numbers for? Give me a shout on Twitter or leave a comment below and we’ll figure out something!

Also, make sure you check out the full stats here.


Random Interesting Facts on HTML/SVG usage is a post from CSS-Tricks

Categories: Designing, Others Tags:

Web Development Reading List #160: Real Stories About HTTP/2, Cascading Style Sheets, And Code Of Shame

November 25th, 2016 No comments

We have great new technology available to enhance our websites. But while theoretical articles explain well what the technologies do, we often struggle to find real use cases or details on how things worked out in actual projects.

This week I stumbled across a couple of great posts that share exactly these precious real-life insights: stories about HTTP/2 implementation, experiences from using the Cascade of CSS in large-scale projects, and insights into employing Service Worker and BackgroundSync to build solid forms.

The post Web Development Reading List #160: Real Stories About HTTP/2, Cascading Style Sheets, And Code Of Shame appeared first on Smashing Magazine.

Categories: Others Tags:

StockJo: Extensive Collection With Collections of Free Design Elements and Resources

November 25th, 2016 No comments
StockJo: Landing Page

StockJo is the starting point to a huge variety of content that is relevant to designers. It collects collections, making it some kind of super collection. Particularly for newbies, this can save a ton of time. At StockJo, you’ll find a place to go for everything the heart, or brain, desires.

StockJo: Landing Page

StockJo: Simple Design, Solid Content

You are looking for free photos, videos, textures, mockups, fonts, sound files, vector graphics, illustrations, color palettes, small tools, tutorials, HTML templates, and other web resources? If so, Stockjo is a good landing page for you.

Created and run by the Indian agency Infiyo, the rather new offer called StockJo provides you with access to all the little helpers that might be interesting for professional designers.

Regular readers of Noupe know that, over the past years, a trend of creating new collections with free content has risen, but even frequent readers are struggling to keep track of them all. At this point, I’d like to point you to our collection post with 43 hand-picked services for free photos, which is even more extensive than StockJo’s supply regarding photography.

In return, StockJo is a lot more widespread overall and collects content related to the much wider range of topics mentioned above. Thus, you can always check StockJo first, no matter what you’re looking for.

StockJo: Category Example

StockJo: Category Example

There are two different ways to access the listed resources. For one, you could use the free text search, which results can be refined in a second step, by filtering the results by licenses, for example. Another way is simply looking through the categories. As of right now, this is still a valid option, as the amount of listed collections is still rather assessable.

In the categories, you’ll find lists with entries that are all linked to the category’s starting page, and also give you an idea of what to expect by providing a short description. Tags with information on the license tell you what you are allowed to do with the content. The classic heart icon lets you “like” a list entry.

StockJo: Additional Tags Inform You About the License

StockJo: Additional Tags Inform You About the License

Unfortunately, clicking the tags leads to the 404. The same happens when trying to access the blog linked from the top navigation. Infiyo still has some homework to do here. Let’s assume that that’s only the case because StockJo is a work in progress and a fresh one.

Apart from these irregularities, StockJo is worth a bookmark and belongs into the toolbox of not only every designer but pretty much every page operator. It’s not the universal solution to all issues, but very useful nonetheless. Take a look for yourself.

Categories: Others Tags:

Everything you need to know about Layers and Symbols in Adobe XD

November 24th, 2016 No comments
dansky_layers-symbols-in-adobe-xd

In this tutorial, we’re going to take a look at Layers and Symbols in Adobe XD.

Download Adobe Experience Design CC (Adobe XD).

Read More at Everything you need to know about Layers and Symbols in Adobe XD

Categories: Designing, Others Tags:

Apply to 100 tech companies with 1 application

November 24th, 2016 No comments

Indeed Prime helps tech talent such as UX/UI designers and software developers simplify their job search and land their dream job. Candidates get immediate exposure to the best tech companies with just one simple application to Indeed Prime. Companies on Prime’s exclusive platform message candidates with salary and equity upfront. The average software developer gets 5 employer contacts and an average salary offer of $125,000. Indeed Prime is 100% free for candidates – no strings attached. And when you’re hired, Indeed Prime gives you a $2,000 bonus to say thanks for using Prime! Sign up now at indeed.com/prime.

Direct Link to ArticlePermalink


Apply to 100 tech companies with 1 application is a post from CSS-Tricks

Categories: Designing, Others Tags:

High Contrast, A PostCSS Plugin Story*

November 24th, 2016 No comments

The following is a guest post by Eduard Pochtar from ShiwaForce. Eduard is going to walk us through they why and how of a plugin he and his team built to process existing CSS to make a high contrast version of a web site. It involved a little thinking and a little strong arming to make it happen.

*Based on true events

It’s hard to imagine life without internet today. Many people’s lives are less or more tied with internet. Think about everything we rely on it for: communication, education, shopping, business control, home management, entertainment, etc. It’s like a world inside another world, with it’s own rules and diversity.

Around 80 million people in the EU are disabled and this number is growing. The unfortunate truth is that many of them can’t use all the opportunity of the internet, because so many of them don’t care about accessibility.

What can we do about this?

It’s a good question. We live in a time when technologies can help us to take care of people who need special care. More and more organizations, companies, even governments are getting involved to help people with disabilities.

Web Accessibility Law

Not so long ago the EU passed a law about web accessibility. This law covers public sector websites and mobile apps, like administrations, police departments, public hospitals, universities, and libraries. It will require them to be accessible for all citizens – in particular for the blind, the hard of hearing, the deaf, and those with low vision and with functional disabilities.

New rules accepted in the EU web accessibility directive are:

  • All websites or web applications owned by EU-member governments must be fully accessible to people with disabilities. New websites must be accessible and existing content must be updated.
  • Archival content and documents will be available on demand in accessible form.
  • Government videos must be closed captioned. Live video has a window of 14 days since first broadcast to get captions.
  • Online services, like paying fines or fees, will have to be accessible.
  • EU government websites must indicate if (and why) parts of their website are inaccessible.
  • EU member states must regularly monitor and report to both the public and the European Commission on the accessible status of their web services.

In a press release, Günther H. Oettinger, Commissioner for the Digital Economy and Society, stated:

It is not acceptable that millions of European citizens are left behind in the digital society. The agreement that we have just reached will ensure that everyone has the same opportunity to enjoy the benefits of the internet and mobile apps, to participate in society to a fuller extent and to lead a more independent life.

Echoing that sentiment, Andrus Ansip, Vice-President for the Digital Single Market, said:

Internet access should be a reality for everyone. Leaving millions of Europeans behind is not an option. Tonight’s agreement is an important step towards a Digital Single Market, which is about removing barriers so that all Europeans can get the best from the digital world.

I think it’s very important to understand that internet is the place where everyone is equal. And I think that nowadays, internet de facto should be accessible, in one or another form, for as more users as possible.

I would like to share our story about how we developed a tool that helps to develop a high contrast version of a website.

Contrast Matters

Contrast makes it easy to distinguish one thing from another. In web design, contrast usually refers to the difference between the foreground and background of text. In other words, how different are the words on the screen from the background they sit on.

Text contrast is an important accessibility criterion. When people use websites or apps, they don’t read, they scan. When most people scan or read quickly, they rely on word and character shapes rather than more explicitly conscious strategies like analyzing each letter and the order in which it appears. You’re probably doing that right now, by using good contrast text that makes those shapes easy to immediately recognize.

High Contrast

In some countries government requires from public websites special high contrast version of the website with inverted colors. You may know them by this kind of icon:

This high contrast setting benefits users with low vision or other visual disabilities.

The Challenge

Not so long ago our team has faced the project that required high contrast version. And it was a big challenge for all of us.

First of all we were digging all over the internet researching information about what is high contrast and how should it work. Unfortunately, we didn’t find enough information. Everything was very abstract and poor. But some information we did find useful. The background should be dark (black), text – opposite color of the background (white), links – yellow or green.

Some websites may even invert images, some may completely remove images from high-contrast version.

CSS Preprocessors

One way to build a high contrast version of a site is by using preprocessors like Less, Sass, or Stylus. Preprocessors also give us a lot of ways to compile two versions of website. For example it can be variables:

$high-contrast: true;
$background-color: #fff;
$background-high-contrast-color: #000;
$text-color: #000;
$text-high-contrast-color: #fff;

body {
  …
  @if $high-contrast == true {
    background-color: $background-high-contrast-color;
  } else {
    background-color: $background-color;
  }
  …
}
…
.text {
  @if $high-contrast == true {
    color: $text-color;
  } else {
    color: $text-high-contrast-color;
  }
}

This might make our CSS a bit complicated and hard to maintain. Here’s another way, @mixins:

$high-contrast: true;
$background-color: #fff;
$background-high-contrast-color: #000;
$text-color: #000;
$text-high-contrast-color: #fff;

@mixin background-color {
  @if $high-contrast == true {
    background-color: $background-high-contrast-color;
  } @else {
    background-color: $background-color;
  }
}

@mixin text-color {
  @if $high-contrast == true {
    color: $text-high-contrast-color;
  } @else {
    color: $text-color;
  }
}

body {
  …
  @include background-color;
  …
}
…
.text {
  @include text-color;
}

This method is a little bit better, but still has disadvantages. There are tons of other ways how to develop high contrast version. Each one has its own advantages and disadvantages.

But what if you don’t use a preprocessor? Or what if your project is already under development and variables or mixins are not used properly or missing at all?

We have faced this problem. While one part of the team was researching high contrast and ways to integrate it into the development process, another part of the team already was developing the project. Plus, unfortunately, they didn’t use a preprocessor at all.

A Plugin Idea!

Fortunately for us, we already knew about PostCSS and all its possibilities. The great thing about PostCSS for us was that we could just modify or replace those properties or values that we needed, everything else could stay untouched. Isn’t that great? This is why we decided to create the PostCSS High Contrast plugin.

Developing The PostCSS Plugin

At first, it seemed like one more challenge for us. No one had no idea how to write a PostCSS Plugin. We were surprised how easy it was. PostCSS has great documentation and community and this is very helpful especially for newbies like us.

After an hour of looking through PostCSS documentation, we were able to start with our plugin. PostCSS has really great API. Look at these few lines of js:

css.walkRules( function (rule) {
  if (rule.selector === 'body') {
    // do something…
  }
});

They speak for themselves!

But still, we faced a bunch of other problems:

  • What colors to change and what colors leave untouched?
  • What if colors are inherited from parent elements?
  • What if colors are already high contrast?
  • What if it is complex element, which is not that easy to modify, change it’s color or background-color?

We had a lot of questions. We didn’t know how to move forward.

First of all we had to decide what colors to change and what colors leave untouched. We tried to find out if each color is high contrast enough or not by checking it’s brightness and saturation:

 var declColor = color(decl.value).hsl();    
if (declColor.s > 50 && declColor.l > 50){
  decl.value = '#000';
}

But after some testing of this approach, we decided it didn’t fit very well for us. It was very complicated, sometimes it didn’t work as we expected, and it took more time to compile our CSS. We realized that the best way would be just to replace all the colors no matter what:

if (decl.prop === 'background-color') {
  decl.value = #000;
}

if (decl.prop === 'color') {
  decl.value = #fff;
}

This seemed to work great. After celebrating our another small win, we noticed that not all elements were affected. Investigation of the problem showed that not all elements have color properties. CSS inheritance! To solve this issue we decided to create “aggressive mode”.

“Aggressive mode” accepts a list of selectors that will get color property no matter what.

postcss([
  require('postcss-high-contrast')({
    aggressiveHC: true,
    aggressiveHCDefaultSelectorList: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'li', 'th', 'td'],
    aggressiveHCCustomSelectorList: ['div', 'span'],
  })
])

After few more different tests, it seemed that our plugin was finished.

How does it work?

Before I finish our story, I would like to describe how to use PostCSS High Contrast Plugin. I hope you are already familiar with PostCSS and its ecosystem. If not check out PostCSS website. No matter what your preprocessor preference, you can additionally use PostCSS. This means that PostCSS High Contrast plugin will work with any CSS.

Here’s an example configuration:

postcss([
  require('postcss-high-contrast')({
    aggressiveHC: true,
    aggressiveHCDefaultSelectorList: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'li', 'th', 'td'],
    aggressiveHCCustomSelectorList: ['div', 'span'],

    backgroundColor: '#000',
    altBgColor: '#fff',

    textColor: '#fff',

    linkColor: '#fcff3c',
    linkHoverColor: '#fcff3c',

    borderColor: '#fff',
    disableShadow: true,

    imageFilter: 'invert(100%)',
    imageSelectors: ['img'],

    removeCSSProps: false,
    CSSPropsWhiteList: ['background', 'background-color', 'color', 'border', 'border-top', 'border-bottom',
      'border-left', 'border-right', 'border-color', 'border-top-color', 'border-right-color',
      'border-bottom-color', 'border-left-color', 'box-shadow', 'filter', 'text-shadow']
  })
])

Normal mode example:

/* Before */
body {
  background: #fff;
  color: #000;
}

a {
  color: #0b39e1;
}

/* After */
body {
  background: #000;
  color: #fff;
}

a {
  color: #fcff3c;
}

Aggressive mode example:

/* Before */
h1 {
  font-size: 48px;
  margin: 0;
  padding: 0 24px;
  width: 100%;
}

p {
  font-size: 48px;
  margin: 0 0 24px;
}

/* After */
h1 {
  color: #fff;
  font-size: 48px;
  margin: 0;
  padding: 0 24px;
  width: 100%;
}

p {
  color: #fff;
  font-size: 48px;
  margin: 0 0 24px;
}

The End

It was great experience for us to develop the PostCSS High Contrast Plugin. I would like to thank the PostCSS team for the great tool, documentation, and API. We never imagined it would be so easy.

We live in a wonderful time. We have so many technologies that help us everyday and the internet is one of the most important. So let’s try to make it more accessible to everyone.


High Contrast, A PostCSS Plugin Story* is a post from CSS-Tricks

Categories: Designing, Others Tags: