Skip to main content

A Brief Note on Highlighted Text

sidebar.iosidebar.io2 weeks ago in#Web Design Love23

TL;DR: If you plan to style text highlighted by the browser, you must give it sufficient contrast — 3:1 for the highlight block against its background and (probably) 4.5:1 for the text within that highlighted block against that background. CSS Context CSS provides methods to style the highlights that browsers apply from selected text (::selection), link target text (::target-text), and spelling & grammar error text (::spelling-error and ::grammar-error). To limit layout shifts, the spec only allows setting background-color, color, text-decoration (and its associated properties), text-shadow, stroke-color, fill-color, and stroke-width. The CSS Pseudo-Elements Module Level 4 Working Draft specification covers this in § 3. Highlight Pseudo-elements, including the allowed properties. When using Windows High Contrast Mode / Contrast Themes / forced-colors, ::target-text will use CSS system color keywords MarkText and Mark. While ::selection will use HighlightText and Highlight. Conversely, ::spelling-error and ::grammar-error use text-decoration, not background / foreground colors. According to Delan Azabani on Mastodon, Igalia is working on bringing find-in-page pseudo element selectors (::search-text and ::search-text:current) to at least Chromium while acting on the CSSWG issue for same. I could not find what system color keywords it would use (though I just asked). WCAG Context WCAG SC 1.4.3: Contrast (Minimum) requires a contrast ratio of at least 4.5:1 for text against its background. Larger or bolder text can get by with a 3:1 contrast ratio. SC 1.4.11 Non-text Contrast similarly requires a 3:1 contrast ratio to distinguish a UI component’s state (such as selected). This may be against the page background or it may be the background of the container. Which means this highlight color may need to be defined more than once in your page (and the text along with it). When you pair these two Success Criteria, it means your highlight background needs a 3:1 contrast ratio against its own background and the text will need a 4.5:1 (unless bold / large) contrast ratio against that. As a curve ball, SC 1.4.1 Use of Color states that color is not the only method used to convey information or distinguish a visual element. The challenge is that the limited styles the CSS specification allows are mostly color, with the obvious exceptions of text-decoration (and its associated properties), text-shadow, and stroke-width. It may be impractical to lean on these in many contexts, but I expect the AGWG will get dragged into it at some point (see the discussion on visited / unvisited links for example) You may have noticed that default user agent styles regularly have contrast issues. That doesn’t make them ok, but they are outside the scope of WCAG. As soon as you modify the browser’s default styles, you are on the hook for conforming to WCAG. Consider this note for the WCAG definition of contrast ratio (relevant bits highlighted): WCAG conformance should be evaluated for color pairs specified in the content that an author would expect to appear adjacent in typical presentation. Authors need not consider unusual presentations, such as color changes made by the user agent, except where caused by authors’ code. Also, 1.4.11 has this carve-out: …except […] where the appearance of the component is determined by the user agent and not modified by the author. Essentially, if you touch it, you own it. Other posts of mine about customizing what are otherwise system defaults and are often fine if you don’t mess with them: WHCM and System Colors Baseline Rules for Scrollbar Usability Wrap-up If you plan to style text highlighted by the browser,  » Read More

Like to keep reading?

This article first appeared on sidebar.io. If you'd like to continue this story, follow the white rabbit.

View Full Article

Let's talk about Web Design

The term "web design" describes the layout of websites that are seen online. Instead of software development, it typically refers to the user experience components of website development. The primary focus of web design used to be creating websites for desktop browsers, but from the middle of the 2010s, designing for mobile and tablet browsers has gained significance.

What is a webdesigner?

A web designer is responsible for a website's look, feel, and occasionally even content. For instance, appearance refers to the colors, text, and images utilized. Information's organization and categorization are referred to as its layout. An effective web design is user-friendly, aesthetically pleasing, and appropriate for the target audience and brand of the website. Many websites focus on keeping things simple so that viewers won't be distracted or confused by additional information and functionality. Removing as many potential sources of user annoyance as possible is a crucial factor to take into account because the foundation of a web designer's output is a site that gains and nurtures the trust of the target audience.

Responsive and adaptive design are two of the most popular techniques for creating websites that function well on both desktop and mobile devices. In adaptive design, the website content is fixed in layout sizes that correspond to typical screen sizes, while in responsive design, information moves dynamically based on screen size. A layout that is as consistent as possible across devices is essential to preserving user engagement and trust. Designers must be cautious when giving up control of how their work will appear because responsive design can be challenging in this area. While they might need to diversify their skill set if they are also in charge of the content, they will benefit from having complete control over the final output.

What does a web design worker do?

A web designer is a member of the IT industry who is in charge of planning a website's structure, aesthetic appeal, and usability.

A skilled site designer must possess both technical know-how and creative graphic design abilities. They must be able to envision how a website will seem (its graphical design) and how it will operate (conversion of a design into a working website).

The terms web developer and designer are frequently used interchangeably but erroneously. In order to construct more complex interactions on a website, such as the integration with a database system, a web developer is frequently more likely to be a software developer who works with programming languages.