outline – CSS-Tricks https://css-tricks.com Tips, Tricks, and Techniques on using Cascading Style Sheets. Fri, 28 Oct 2022 12:45:48 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/07/star.png?fit=32%2C32&ssl=1 outline – CSS-Tricks https://css-tricks.com 32 32 45537868 Fancy Image Decorations: Outlines and Complex Animations https://css-tricks.com/fancy-image-decorations-outlines-and-complex-animations/ https://css-tricks.com/fancy-image-decorations-outlines-and-complex-animations/#comments Fri, 28 Oct 2022 12:45:47 +0000 https://css-tricks.com/?p=374302 We’ve spent the last two articles in this three-part series playing with gradients to make really neat image decorations using nothing but the <img> element. In this third and final piece, we are going to explore more techniques using the …


Fancy Image Decorations: Outlines and Complex Animations originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
We’ve spent the last two articles in this three-part series playing with gradients to make really neat image decorations using nothing but the <img> element. In this third and final piece, we are going to explore more techniques using the CSS outline property. That might sound odd because we generally use outline to draw a simple line around an element — sorta like border but it can only draw all four sides at once and is not part of the Box Model.

We can do more with it, though, and that’s what I want to experiment with in this article.

Fancy Image Decorations series

Let’s start with our first example — an overlay that disappears on hover with a cool animation:

We could accomplish this by adding an extra element over the image, but that’s what we’re challenging ourselves not to do in this series. Instead, we can reach for the CSS outline property and leverage that it can have a negative offset and is able to overlap its element.

img {
  --s: 250px; /* the size of the image */
  --b: 8px;   /* the border thickness*/
  --g: 14px;  /* the gap */
  --c: #4ECDC4;

  width: var(--s);
  aspect-ratio: 1;
  outline: calc(var(--s) / 2) solid #0009;
  outline-offset: calc(var(--s) / -2);
  cursor: pointer;
  transition: 0.3s;
}
img:hover {
  outline: var(--b) solid var(--c);
  outline-offset: var(--g);
}

The trick is to create an outline that’s as thick as half the image size, then offset it by half the image size with a negative value. Add in some semi-transparency with the color and we have our overlay!

Diagram showing the size of the outline sround the image and how it covers the image on hover.

The rest is what happens on :hover. We update the outline and the transition between both outlines creates the cool hover effect. The same technique can also be used to create a fading effect where we don’t move the outline but make it transparent.

Instead of using half the image size in this one, I am using a very big outline thickness value (100vmax) while applying a CSS mask. With this, there’s no longer a need to know the image size — it trick works at all sizes!

Diagram showing how adding a mask clips the extra outline around the image.

You may face issues using 100vmax as a big value in Safari. If it’s the case, consider the previous trick where you replace the 100vmax with half the image size.

We can take things even further! For example, instead of simply clipping the extra outline, we can create shapes and apply a fancy reveal animation.

Cool right? The outline is what creates the yellow overlay. The clip-path clips the extra outline to get the star shape. Then, on hover, we make the color transparent.

Oh, you want hearts instead? We can certainly do that!

Imagine all the possible combinations we can create. All we have to do is to draw a shape with a CSS mask and/or clip-path and combine it with the outline trick. One solution, infinite possibilities!

And, yes, we can definitely animate this as well. Let’s not forget that clip-path is animatable and mask relies on gradients — something we covered in super great detail in the first two articles of this series.

I know, the animation is a bit glitchy. This is more of a demo to illustrate the idea rather than the “final product” to be used in a production site. We’d wanna optimize things for a more natural transition.

Here is a demo that uses mask instead. It’s the one I teased you with at the end of the last article:

Did you know that the outline property was capable of so much awesomeness? Add it to your toolbox for fancy image decorations!

Combine all the things!

Now that we have learned many tricks using gradients, masks, clipping, and outline, it’s time for the grand finale. Let’s cap off this series by combine all that we have learned the past few weeks to showcase not only the techniques, but demonstrate just how flexible and modular these approaches are.

If you were seeing these demos for the first time, you might assume that there’s a bunch of extra divs wrappers and pseudo-elements being used to pull them off. But everything is happening directly on the <img> element. It’s the only selector we need to get these advanced shapes and effects!

Wrapping up

Well, geez, thanks for hanging out with me in this three-part series the past few weeks. We explored a slew of different techniques that turn simple images into something eye-catching and interactive. Will you use everything we covered? Certainly not! But my hope is that this has been a good exercise for you to dig into advanced uses of CSS features, like gradients, mask, clip-path, and outline.

And we did everything with just one <img> element! No extra div wrappers and pseudo-elements. Sure, it’s a constraint we put on ourselves, but it also pushed us to explore CSS and try to find innovative solutions to common use cases. So, before pumping extra markup into your HTML, think about whether CSS is already capable of handling the task.

Fancy Image Decorations series


Fancy Image Decorations: Outlines and Complex Animations originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
https://css-tricks.com/fancy-image-decorations-outlines-and-complex-animations/feed/ 3 374302
outline-color https://css-tricks.com/almanac/properties/o/outline-color/ Wed, 01 Sep 2021 17:54:41 +0000 https://css-tricks.com/?page_id=350656 The outline-color CSS property specifies the color of an element’s outline. What’s an outline? An outline is a line that is drawn around elements — outside the border edge — that is used for accessibility or decoration purposes when that …


outline-color originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
The outline-color CSS property specifies the color of an element’s outline. What’s an outline? An outline is a line that is drawn around elements — outside the border edge — that is used for accessibility or decoration purposes when that element is in focus.

button {
  outline-color: #e435;
}

outline-color is a constituent property in the outline shorthand and is defined in the CSS Basic User Interface Module Level 4 specification which is currently in Editor’s Draft status.

Usage

We usually set the outline of an element using the shorthand property:

a:focus {
  outline: 0.1em solid darkgray;
}

Syntax

outline-color: <color>| invert
  • Initial value: invert (currentColor, in case invert is not supported)
  • Applies to: all elements
  • Inherited: no
  • Computed value: For the keyword invert, the computed value is invert. For the color value, if the value is translucent, the computed value will be the rgba() corresponding one. If it isn’t, it will be the rgb() corresponding one. The transparent keyword maps to rgba(0,0,0,0).
  • Animation type: discrete

Values

/* Keyword value */
outline-color: invert;

/* <color> values */
outline-color: #333;
outline-color: darkorange;
outline-color: hsl(210,100%,44%);

/* Global values */
outline-width: initial;
outline-width: inherit;
outline-width: unset;
  • <color>: Defines the color of the outline and accepts <rgb()>, <rgba()>, <hsl()>, <hsla()>, <hex-color>, <named-color>, currentcolor and <deprecated-system-color>
  • invert: The default value. Specifies an inverted value of the background color of where the outline is rendered, therefore it ensures that the outline is visible.
  • initial: Applies the property’s default setting, which is invert.
  • inherit: Adopts the outline-color value of the parent.
  • unset: Removes the current outline-color from the element.

According to specs, If the browser doesn’t support the invert value, then the initial value of the outline-color property is the currentColor keyword, but at the time of writing, invert is considered invalid in all modern browsers. You can check the browser support at caniuse.

Example

The following example makes the outline of the button red once it’s focused:

button {
  outline-width: 1px;
  outline-style: solid;
  outline-color: gray;
}

button:focus {
  outline-color: red;
}    

Accessibility

An outline is typically used to indicate focus on elements, which can be useful for non-mouse interactions for accessibility reasons and it can generally benefit all users.

It’s very likely that you would want to change the outline color to match your brand or to make it more noticeable. And this is when outline-color comes in handy. But make sure your custom color meet WCAG’s requirements, particularly Success Criterion 2.4.7 which details a visible focus state.

Not only we need to ensure that the contrast ratio between the outline color and the background it’s on is high enough to ensure clear visibility, but also in cases where there is no space between the outline and the element — then we need to check the contrast ratio between the outline color and the background of the element itself.

Non-text UI controls, like buttons, must have a color contrast ratio of at least 3:1 against adjacent colors, according to WCAG Success Criterion 1.4.3.

Two blue buttons with white labels that say button. The button on the left has a dark blue outline while the button on the right has a black outline. The button on the left fails the 3.1 contrast ratio requirement with a 1.89.1 ration, while the right button passes with a 3.6.1 ratio.
A dark blue outline color, left, provides insufficient contrast compared to a black outline.

Sara Soueidan explains this very well in her “A guide to designing accessible, WCAG-compliant focus indicators” article. You can learn a lot more about WCAG’s contrast ratios and how they’re determined in Stacy Arellano’s deep dive article.

Demo

Play with outline properties in the following demo:

Browser support

IEEdgeFirefoxChromeSafariOpera
8+AllAllAllAllAll
Android ChromeAndroid FirefoxAndroid BrowseriOS SafariOpera Mobile
AllAll92+All64+
Source: caniuse

More information

Tips and tricks

Good resources


outline-color originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
350656
outline-style https://css-tricks.com/almanac/properties/o/outline-style/ Mon, 16 Aug 2021 13:55:00 +0000 https://css-tricks.com/?page_id=346652 The outline-style CSS property specifies the style of an element’s outline. What’s an outline? An outline is a line that is drawn around elements — outside the border edge — that is used for accessibility or decoration purposes when that …


outline-style originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
The outline-style CSS property specifies the style of an element’s outline. What’s an outline? An outline is a line that is drawn around elements — outside the border edge — that is used for accessibility or decoration purposes when that element is in focus.

button {
  outline-style: dashed;
}

outline-style is a constituent property in the outline shorthand and is defined in the CSS Basic User Interface Module Level 4 specification which is currently in Editor’s Draft status.

Usage

We usually set the outline of an element using the shorthand property:

a:focus {
  outline: 5px dashed black;
}

Accessibility

By default, different user agents provide different outline styling on focused elements to help indicate non-mouse interactions for accessibility reasons, but that visual is generally beneficial to everyone. This styling is typically an outline around the element.

In Chrome, the outline style is a solid; in Firefox it is a lighter, partially dotted one.

There are some reasons why you would want to change the default outline style:

  • You can set that style to match your brand.
  • You can make the outline more noticeable.
  • You can bring more attention to the user by changing the outline style on the element’s focus.

And this is when outline-style comes in handy. But make sure your custom style is, at the very least, as accessible as the default style. That means making it clear and noticeable, while not trying to steer too far that it no longer resembles a focus state. Eric Bailey has a lot of great advice on this in his “Focusing on Focus Styles” article.

Syntax

outline-style: auto | <outline-line-style>

/* where */
<outline-line-style> = none | dotted | dashed | solid | double | groove | ridge | inset | outset
  • Initial value: none
  • Applies to: all elements
  • Inherited: no
  • Computed value: as specified
  • Animation type: discrete

Values

/* Keyword values */
outline-style: auto;
outline-style: none;
outline-style: dotted;
outline-style: dashed;
outline-style: solid;
outline-style: double;
outline-style: groove;
outline-style: ridge;
outline-style: inset;
outline-style: outset;

/* Global values */
outline-width: initial;
outline-width: inherit;
outline-width: unset;
A three-by-three grid of boxes that are evenly spaced in white against a gradient that goes from bright orange to dark orange. Each box demonstrates an outline-style property value.
  • auto: Allows user agents to draw a custom outline style on elements.
  • none: The default value. Outline is not drawn. The computed value of outline-width is 0.
  • dotted: Draws a bunch of round dots around the element.
  • dashed: Draws square-ended dashes around the element.
  • solid: A single line wraps around the element.
  • double: Draws two parallel solid lines along the element’s edge, with space between them. The thickness of the two lines and the gap between them is equal to the outline-width value. The outline-width must be at least 3px wide for the double outline to be visible.
  • groove: The outline looks like it’s carved in the page. This carved effect usually comes from the color specified using the outline-color property, plus a slightly darker version of it that the browser figures out on its own.
  • ridge: The opposite of groove, where the outline looks as if it’s coming off of the page.
  • inset: Gives the element’s box an embedded appearance, as if the content inside of the outline is sinking into the page.
  • outset: The opposite of inset, giving the element’s box an embossed appearance, as if the content inside of the outline is coming out of the page.
  • initial: Applies the property’s default setting, which is none.
  • inherit: Adopts the outline-style value of the parent.
  • unset: Removes the current outline-style from the element.

Example

The following example makes the outline of the button double once it’s focused:

button {
  outline-width: 1px;
  outline-style: solid;
  outline-color: lightblue;
}

button:focus {
  outline-style: double;
}

Demo

You can play around this property in the following demo:

Browser support

IEEdgeChromeFirefoxSafariOpera
8+AllAllAllAllAll
iOS SafariAndroid ChromeAndroid FirefoxAndroid BrowserOpera Mobile
AllAllAllAllAll
Source: caniuse

More documentation

CSS tricks!


outline-style originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
346652
Using the `outline` Property as a Collapsable Border https://css-tricks.com/using-the-outline-property-as-a-collapsable-border/ https://css-tricks.com/using-the-outline-property-as-a-collapsable-border/#comments Fri, 18 Jun 2021 20:38:59 +0000 https://css-tricks.com/?p=341511 The outline property in CSS draws a line around the outside of an element. This is quite similar to the border property, the main exception being that outline isn’t a part of the box model. It is often used for …


Using the `outline` Property as a Collapsable Border originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
The outline property in CSS draws a line around the outside of an element. This is quite similar to the border property, the main exception being that outline isn’t a part of the box model. It is often used for highlighting elements, for example, the :focus style.

In this article, let’s put a point on it, leaning into what outline is good at:

  1. They can be collapsed with each other (trickery!) because they technically “take up no space.”
  2. Showing and hiding outlines, or changing outline-width, doesn’t trigger layouts (which is good for performant animations and transitions).

Easier faux-table cell borders

Below is an example of a list that is laid out as a grid, making it look a bit like a table layout. Every cell has a minimum width, and will grow/shrink as the container becomes wider/narrower.

We could use border to pull this off, like this:

But in order to make an even border around each cell — never doubling up or missing — it’s a cumbersome process. Above, I used a border on all sides of each “cell” then negative margins to overlap them and prevent doubling. That meant clipping off the border on two sides, so the borders had to be re-applied there on the parent. Too much fiddly work, if you ask me.

Even having to hide the overflow is a big ask, which you have to do because, otherwise, you’ll trigger scrollbars unless you resort to even thicker trickery, like using absolutely-positioned pseudo elements.

Showing a flat table with seven columns and four rows, each cell numbered sequentially, 1 through 28. The table has a white background and block text and the borders are black around each cell with ample padding.

Check out the same result, visually, only using outline instead:

The code here is much cleaner. There is no real trickery at play. Each “cell” just has an outline around it, and that’s it.

Border in animation

Changing border-width will always trigger layout, no matter if it is actually needed.

Showing the paint rendering results from a performance test where a layout change is shown in the middle of the results taking 58.4 milliseconds to complete.

In addition, due to Chrome’s special handling of sub-pixels for border widths, animating the border-width property makes the entire border shake (which I think is strange). Firefox doesn’t have this issue.

Showing another performance test, this time with no layout triggered in the results.

There are pros and cons when it comes to animating borders. Check out Stephen Shaw’s post from a while back for an example of the performance implications.

There are some gotchas

Of course there are. Like most other CSS properties, there are a few “gotchas” or things to know when working with the outline property:

  1. Rounded outlines are only supported in Firefox at the time of writing. I imagine other browsers will eventually support them as well.
  2. An outline always goes around all the sides. That is to say it’s not a shorthand property like, say, border; so no outline-bottom, and so on.

But we can work around these limitations! For example, we can use add a box-shadow with no blur radius as an alternative. But remember: box-shadow has a higher performance cost than using either outline and border.

That’s it!

Will you always be working on something that calls for faking a table with an unordered list? Unlikely. But the fact that we can use outline and its lack of participation in the box model makes it interesting, particularly as a border alternative in some cases.

Maybe something like this tic-tac-toe board Chris put together several years ago could benefit from outline, instead of resorting to individually-crafted cell borders. Challenge accepted, Mr. Coyier? 😉


Using the `outline` Property as a Collapsable Border originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
https://css-tricks.com/using-the-outline-property-as-a-collapsable-border/feed/ 7 341511
Platform News: Rounded Outlines, GPU-Accelerated SVG Animations, How CSS Variables Are Resolved https://css-tricks.com/platform-news-rounded-outlines-gpu-accelerated-svg-animations-how-css-variables-are-resolved/ https://css-tricks.com/platform-news-rounded-outlines-gpu-accelerated-svg-animations-how-css-variables-are-resolved/#comments Fri, 02 Apr 2021 19:35:28 +0000 https://css-tricks.com/?p=337636 In the news this week, Firefox gets rounded outlines, SVG animations are now GPU-accelerated in Chrome, there are no physical units in CSS, The New York Times crossword is accessible, and CSS variables are resolved before the value is inherited.…


Platform News: Rounded Outlines, GPU-Accelerated SVG Animations, How CSS Variables Are Resolved originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
In the news this week, Firefox gets rounded outlines, SVG animations are now GPU-accelerated in Chrome, there are no physical units in CSS, The New York Times crossword is accessible, and CSS variables are resolved before the value is inherited.

Let’s jump in the news!

Rounded outlines are coming to Firefox

The idea to have the outline follow the border curve has existed ever since it became possible to create rounded borders via the border-radius property in the mid 2000s. It was suggested to Mozilla, WebKit, and Chromium over ten years ago, and it’s even been part of the CSS UI specification since 2015:

The parts of the outline are not required to be rectangular. To the extent that the outline follows the border edge, it should follow the border-radius curve.

Fast-forward to today in 2021 and outlines are still rectangles in every browser without exception:

But this is finally starting to change. In a few weeks, Firefox will become the first browser with rounded outlines that automatically follow the border shape. This will also apply to Firefox’s default focus outline on buttons.

Three sets of round yellow buttons, comparing how Chrome, Firefox, and Safari handle outlines.

Please star Chromium Issue #81556 (sign in required) to help prioritize this bug and bring rounded outlines to Chrome sooner rather than later.

SVG animations are now GPU-accelerated in Chrome

Until recently, animating an SVG element via CSS would trigger repaint on every frame (usually 60 times per second) in Chromium-based browsers. Such constant repainting can have a negative impact on the smoothness of the animation and the performance of the page itself.

The latest version of Chrome has eliminated this performance issue by enabling hardware acceleration for SVG animations. This means that SVG animations are offloaded to the GPU and no longer run on the main thread.

Side by side comparison of the Performance tab in Chrome DevTools.
In this example, the SVG circle is continuously faded in and out via a CSS animation (see code)

The switch to GPU acceleration automatically made SVG animations more performant in Chromium-based browsers (Firefox does this too), which is definitely good news for the web:

Hooray for more screen reader-accessible, progressively enhanced SVG animations and less Canvas.

There cannot be real physical units in CSS

CSS defines six physical units, including in (inches) and cm (centimeters). Every physical unit is in a fixed ratio with the pixel unit, which is the canonical unit. For example, 1in is always exactly 96px. On most modern screens, this length does not correspond to 1 real-world inch.

The FAQ page of the CSS Working Group now answers the question why there can’t be real physical units in CSS. In short, the browser cannot always determine the exact size and resolution of the display (think projectors). For websites that need accurate real-world units, the Working Group recommends per-device calibration:

Have a calibration page, where you ask the user to measure the distance between two lines that are some CSS distance apart (say, 10cm), and input the value they get. Use this to find the scaling factor necessary for that screen (CSS length divided by user-provided length).

This scaling factor can then be set to a custom property and used to compute accurate lengths in CSS:

html {
  --unit-scale: 1.428;
}

.box {
  /* 5 real-world centimeters */
  width: calc(5cm * var(--unit-scale, 1));
}

The Times crossword is accessible to screen reader users

The NYT Open team wrote about some of the improvements to the New York Times website that have made it more accessible in recent years. The website uses semantic HTML (<article>, <nav>, etc.), increased contrast on important components (e.g., login and registration), and skip-to-content links that adapt to the site’s paywall.

Furthermore, the Games team made the daily crossword puzzle accessible to keyboard and screen reader users. The crossword is implemented as a grid of SVG <rect> elements. As the user navigates through the puzzle, the current square’s aria-label attribute (accessible name) is dynamically updated to provide additional context.

Screenshot of the crossword game with an open screen reader dialog announcing what is on the screen.
The screen reader announces the clue, the number of letters in the solution, and the position of the selected square

You can play the mini crossword without an account. Try solving the puzzle with the keyboard.

CSS variables are resolved before the value is inherited

Yuan Chuan recently shared a little CSS quiz that I didn’t answer correctly because I wasn’t sure if a CSS variable (the var() function) is resolved before or after the value is inherited. I’ll try to explain how this works on the following example:

html {
  --text-color: var(--main-color, black);
}

footer {
  --main-color: brown;
}

p {
  color: var(--text-color);
}

The question: Is the color of the paragraph in the footer black or brown? There are two possibilities. Either (A) the declared values of both custom properties are inherited to the paragraph, and then the color property resolves to brown, or (B) the --text-color property resolves to black directly on the <html> element, and then this value is inherited to the paragraph and assigned to the color property.

Two CSS rulesets, one as Option A and the other as Option B, both showing how variables are inherited and resolved between elements.

The correct answer is option B (the color is black). CSS variables are resolved before the value is inherited. In this case, --text-color falls back to black because --main-color does not exist on the <html> element. This rule is specified in the CSS Variables module:

It is important to note that custom properties resolve any var() functions in their values at computed-value time, which occurs before the value is inherited.


Platform News: Rounded Outlines, GPU-Accelerated SVG Animations, How CSS Variables Are Resolved originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
https://css-tricks.com/platform-news-rounded-outlines-gpu-accelerated-svg-animations-how-css-variables-are-resolved/feed/ 4 337636
:focus-visible Support Comes to Firefox https://css-tricks.com/focus-visible-support-comes-to-firefox/ https://css-tricks.com/focus-visible-support-comes-to-firefox/#comments Wed, 10 Feb 2021 20:51:56 +0000 https://css-tricks.com/?p=334266 Look at that! The :focus-visible pseudo-selector is now supported in Firefox, as of version 85 which shipped yesterday. I had to rush over to the MDN Docs just to confirm, and yep, the :focus-visible page has been updated to


:focus-visible Support Comes to Firefox originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
Look at that! The :focus-visible pseudo-selector is now supported in Firefox, as of version 85 which shipped yesterday. I had to rush over to the MDN Docs just to confirm, and yep, the :focus-visible page has been updated to reflect the news.

What’s so cool about :focus-visible? It’s all about the blue focus ring that displays around elements that are in focus. It’s sort of a happy medium between loving the outline for accessibility purposes (gotta know what element is selected when tabbing on a keyboard) but not-really-loving how it looks (gotta have everything follow brand).

The strategy has largely been an all-or-nothing choice between using a custom outline when any element is in :focus (great, but that means for both keyboard tabbing and mouse clicks) or ditching the outline altogether (not great, like ever). :focus-visible accomplishes the same thing as :focus, but uses a browser’s knowledge of user inputs (or heuristics) to determine whether the focus is coming from a keyboard or a mouse.

(Are a browser’s heuristics perfect at determining the input? That depends. Things get murky once we start factoring in things like touch interactions.)

That means, we get to remove the default focus ring (yay!) for the right types of interactions (double yay!) and display our own custom styles while we’re at it (triple yay!). Allow me to pluck Andy Adams’ fine example straight from our almanac. Note that :focus-visible cannot remove the focus ring like :focus can, so the two are used together:

.next-image-button:focus {
  outline: none;
}

.next-image-button:focus-visible {
  outline: 3px solid blanchedalmond; /* That'll show 'em */
}

Chrome implemented :focus-visible back in 2018. Firefox had it’s own prefixed version, :-moz-focusring, prior to this implementation. Safari? Go vote for the feature!

Igalia is gathering funding and working on getting it into Safari! Here’s Brian Kardell on this.


:focus-visible Support Comes to Firefox originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
https://css-tricks.com/focus-visible-support-comes-to-firefox/feed/ 9 334266
The :focus-visible Trick https://css-tricks.com/the-focus-visible-trick/ https://css-tricks.com/the-focus-visible-trick/#comments Fri, 16 Oct 2020 19:12:54 +0000 https://css-tricks.com/?p=323313 Always worth repeating: all interactive elements should have a focus style. That way, a keyboard user can tell when they have moved focus to that element.

But if you use :focus alone for this, it has a side effect that …


The :focus-visible Trick originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
Always worth repeating: all interactive elements should have a focus style. That way, a keyboard user can tell when they have moved focus to that element.

But if you use :focus alone for this, it has a side effect that a lot of people don’t like. It means that when you click (with a mouse) on an interactive element, you’ll see the focus style. Arguably, you don’t need that feedback as a mouse user, because you just moved your cursor there and clicked. Whatever you think of that, it’s annoyed so many people over the years that they remove focus styles entirely, which is a gnarly net loss for accessibility on the web.

What if we could apply focus styles only when the keyboard is used to focus something, not the mouse? Lea Verou put a finger on this a few years back:

That was in response to Chrome dropping the feature behind a flag. Clever clever.

Fast forward a couple of years, Chrome is releasing it without a flag. They are on board with Lea’s idea:

By combining :focus-visible with :focus you can take things a step further and provide different focus styles depending on the user’s input device. This can be helpful if you want the focus indicator to depend on the precision of the input device:

/* Focusing the button with a keyboard will show a dashed black line. */
button:focus-visible {
  outline: 4px dashed black;
}
  
/* Focusing the button with a mouse, touch, or stylus will show a subtle drop shadow. */
button:focus:not(:focus-visible) {
  outline: none;
  box-shadow: 1px 1px 5px rgba(1, 1, 0, .7);
}

I might suggest trying those selectors without the button, making them globally applied!

There is more to dig into, so I’ll link up some more stuff here:

  • The Chromium Blog post covers the heuristics of the selector. It’s tricky. It’s like there is an algorithm to determine if :focus-visible is going to match or not, which you just largely need to trust. It also covers the idea that Firefox has long had :-moz-focusring, but the behavior is different enough that they don’t recommend using it if you’re shooting for consistent behavior.
  • Matthias Ott blogged about it with some good info, like using the official polyfill and how to look at the styles properly in DevTools (there is a new checkbox for it).
  • We’ve covered this before. In that, we noted Lea’s tweet that she thought usage would explode when it ships for real. Let’s see (and hope)!
  • Our almanac entry has a bunch of details.


The :focus-visible Trick originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
https://css-tricks.com/the-focus-visible-trick/feed/ 8 323313
Copy the Browser’s Native Focus Styles https://css-tricks.com/copy-the-browsers-native-focus-styles/ https://css-tricks.com/copy-the-browsers-native-focus-styles/#comments Fri, 28 Aug 2020 14:49:08 +0000 https://css-tricks.com/?p=319992 Remy documented this the other day. Firefox supports a Highlight keyword and both Chrome and Safari support a -webkit-focus-ring-color keyword. So if you, for example, have removed focus from something and want to put it back in the same …


Copy the Browser’s Native Focus Styles originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
Remy documented this the other day. Firefox supports a Highlight keyword and both Chrome and Safari support a -webkit-focus-ring-color keyword. So if you, for example, have removed focus from something and want to put it back in the same style as the browser default, or want to apply a focus style to an element when it isn’t directly in focus itself, this can be useful.

For example:

button:focus + span {
  outline: 5px auto Highlight;
  outline: 5px auto -webkit-focus-ring-color;
}

Looks good to me. It’s especially helpful with the sorta weird new Chrome double-outline style that would be slightly tricky to replicate otherwise.

Chrome 84
Safari 13.1
Firefox 80


Copy the Browser’s Native Focus Styles originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
https://css-tricks.com/copy-the-browsers-native-focus-styles/feed/ 3 319992
Having a Little Fun With Custom Focus Styles https://css-tricks.com/having-a-little-fun-with-custom-focus-styles/ https://css-tricks.com/having-a-little-fun-with-custom-focus-styles/#comments Mon, 02 Dec 2019 15:25:39 +0000 https://css-tricks.com/?p=298874 Every front-end developer has dealt or will deal with this scenario: your boss, client or designer thinks the outline applied by browsers on focused elements does not match the UI, and asks you to remove it. Or you might even …


Having a Little Fun With Custom Focus Styles originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
Every front-end developer has dealt or will deal with this scenario: your boss, client or designer thinks the outline applied by browsers on focused elements does not match the UI, and asks you to remove it. Or you might even be looking to remove it yourself.

So you do a little research and find out that this is strongly discouraged, because the focus outline is there for a reason: it provides visual feedback for keyboard navigation (using the Tab key), letting users who can’t use a mouse or have a visual impairment know where they are on the screen.

This button shows a focus state with Chrome’s default outline style.

That doesn’t mean you’re stuck with this outline, though. Instead of removing it, you can simply replace it with something else. That way, you’ll keep your interface accessible and get more flexibility on how it looks, so you can better match your UI.

You can start by removing the default browser outline by selecting the focused state of the element and applying outline: none. Then, you may choose from each of the options ahead to replace it:

Change the background color

This works best for elements that can be filled, such as buttons. Select the focused state of the element and apply a contrasting background color to it. The higher the contrast the better because subtle changes may not be strong enough visual cues, particularly in cases where with color blindness and low-vision.

In the example below, both background and border color change; you may pick either or both.

Click or focus with the Tab key to view how this state looks.

See the Pen
Elements replacing native outline focus with background color
by Lari (@larimaza)
on CodePen.

Change the text color

If the element has any text, you can select the focused state and change its color. This also works for icons applied with mask-image; you can select the icon as a descendant of the focused element and change its background color, like the example button below.

See the Pen
Elements replacing native outline focus with text and icon color
by Lari (@larimaza)
on CodePen.

Again, contrast is key. You may also consider using an underline on text links and making it part of the changed state because, as the Web Content Accessibility Guidelines state:

Color is not used as the only visual means of conveying information, indicating an action, prompting a response, or distinguishing a visual element. (Level A)
Understanding Success Criterion 1.4.1

Apply a box shadow

The box-shadow property can do exactly the same job as the outline, except it’s much more powerful — you can now control its color, opacity, offset, blur radius and spread radius. And if a border-radius is specified, the box shadow follows the same rounded corners.

See the Pen
Elements replacing native outline focus with box shadow
by Lari (@larimaza)
on CodePen.

You can get really creative with this technique (seriously though, don’t do this):

See the Pen
Elements replacing native outline focus with insane box shadow
by Lari (@larimaza)
on CodePen.

This works for virtually any type of focusable element, like toggles, checkboxes, radio buttons and slides.

See the Pen
Toggle and radio button replacing native outline focus with box shadow
by Lari (@larimaza)
on CodePen.

Increase the element’s size

As an alternative to color change, you may also resort to subtle size modification as focus feedback. In this example, we’re using transform: scale.

See the Pen
Elements replacing native outline focus with transform scale
by Lari (@larimaza)
on CodePen.

The key here is subtlety. Extreme size changes may cause content reflow, not to mention a poor experience for those who prefer reduced motion.

Replicate existing hover styles

If the element already has a contrasting hover style, you can simply take that style and apply it for the focused state as well. This is a rather elegant solution, as you don’t have to add any new colors or outlines to the interface.

Here’s an example where both the focus and hover states adopt a high contrast to the background of an element’s default style:

See the Pen
Elements replacing native outline focus with hover styles
by Lari (@larimaza)
on CodePen.

Bonus: Customize the default outline

Everything we’ve looked at so far takes the assumption that we want to remove the focus outline altogether. We don’t have to! In fact, it’s a border that we can customize.

button:focus {
  outline: 3px dashed orange;
}

That’s shorthand and could have been written this way if we want to fine-tune the styles:

button:focus {
  outline-width: 3px;
  outline-style: dashed;
  outline-color: orange;
}

One additional superpower we have is the outline-offset property, which is separate from the outline shorthand property but can be used alongside it to change the position of the focus ring:

button:focus {
  outline: 3px dashed orange;
  outline-offset: 10px;
}

Conclusion

You can mix and match all of these options to get custom styles that look appropriate for each component type within your interface.

And it’s worth repeating: Don’t forget to use stark color contrasts and other visual cues in addition to color when adopting custom focus states. Sure, we all want an experience that aligns with our designs, but we can adhere to good accessibility practices in the process. The W3C recommends this tool to test the contrast of colors values against the WCAG guidelines.


Having a Little Fun With Custom Focus Styles originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
https://css-tricks.com/having-a-little-fun-with-custom-focus-styles/feed/ 9 298874
The div that looks different in every browser https://css-tricks.com/the-div-that-looks-different-in-every-browser/ Fri, 13 Jul 2018 21:14:04 +0000 http://css-tricks.com/?p=273862 It’s not that Martijn Cuppens used User Agent sniffing, CSS hacks, or anything like that to make this quirk div. This is just a plain ol’ <div> using the outline property a la:

div {
  outline: inset 100px green;
  


The div that looks different in every browser originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
It’s not that Martijn Cuppens used User Agent sniffing, CSS hacks, or anything like that to make this quirk div. This is just a plain ol’ <div> using the outline property a la:

div {
  outline: inset 100px green;
  outline-offset: -125px;
}

It looks different in different browsers because browsers literally render something differently in this strange situation.

I happened upon Reddit user spidermonk33’s comment in which they animated the offset to understand it a bit more. I took that idea and made this little video to show them behaving even weirder than the snapshots…

To Shared LinkPermalink on CSS-Tricks


The div that looks different in every browser originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
273862
outline-offset https://css-tricks.com/almanac/properties/o/outline-offset/ Sat, 06 May 2017 12:33:13 +0000 http://css-tricks.com/?page_id=254226 The outline-offset property in CSS offsets a defined outline from an element’s border edge by a specified amount. An outline, which is different from a border, does not take up any space on the page (like an absolutely positioned element) …


outline-offset originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
The outline-offset property in CSS offsets a defined outline from an element’s border edge by a specified amount. An outline, which is different from a border, does not take up any space on the page (like an absolutely positioned element) so the outline can be offset in any amount and it will not affect the position or layout of surrounding elements.

.example {
  outline: solid 2px blue;
  outline-offset: 10px;
}

Outlines defined using the outline property are often used as focus rings, for accessibility. Thus, the outline-offset property allows you to change the position of the focus ring.

Values

outline-offset accepts one kind of value, a length, which can be:

  • 0 (the default)
  • Any other valid length with a specified unit (including negative values)

Note that outline-offset, like outline-width, does not accept percentage values.

Positioning of the Outline

By default an element’s outline is drawn immediately outside the border (or immediately outside where the border would be drawn if a border was defined). Therefore, it’s technically possible to combine outline and border for a two-border effect:

From there, outline-offset can be used to change the position of the outline relative to the border edge. Try the demo below which allows you to interactively change the outline’s offset value using the slider. The value of the offset is displayed on the page as you move the slider:

As mentioned above, outline-offset accepts negative values, which will offset the outline in the opposite direction (towards the center of the element), as shown in the next interactive demo. Notice the outline starts at -40px:

If you view the above demo in Firefox, you’ll notice the outline appears correct at first but when the slider is adjusted the outline doesn’t render smoothly and ends up in the wrong position. Scrolling the element out of view, then back into view, forces the browser to repaint the outline in the correct position. This seems to be a Firefox-only bug.

https://twitter.com/sarasoueidan/status/1335270452235792387?s=12

Not Part of outline Shorthand

Similar to the border property, the outline property is a shorthand that represents three properties: outline-color, outline-style, and outline-width.

The outline-offset property, therefore, is not represented in this or any other shorthand property, so it needs to be declared separately from the defined outline itself.

More Information

Browser Support

This browser support data is from Caniuse, which has more detail. A number indicates that browser supports the feature at that version and up.

Desktop

ChromeFirefoxIEEdgeSafari
4211153.1

Mobile / Tablet

Android ChromeAndroid FirefoxAndroidiOS Safari
1081072.13.2

The “partial” indicator for IE means IE does not support outline-offset, but does support outline shorthand and the three properties it represents.

In addition to the bug mentioned above in the “Positioning of the Outline” section, there is a bug in Firefox where the outline is drawn incorrectly if the element has a child element that overflows the parent boundary (e.g. using negative margins or absolute positioning). Therefore, the outline-offset value will be relative to the extended boundary created by the overflowing child, rather than the original parent element boundaries. To understand this better, see this CodePen, this Stack Overflow thread, and this bug report (credit to reader Matt Vanes for sending in this bug).


outline-offset originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
254226
Text Stroke: Stuck In The Middle With You https://css-tricks.com/text-stroke-stuck-middle/ https://css-tricks.com/text-stroke-stuck-middle/#comments Thu, 02 Mar 2017 12:56:52 +0000 http://css-tricks.com/?p=251936 There is a non-standard way to stroke HTML text (SVG has a standard way). It’s not particularly new. There are -webkit- and -moz- prefixes for it. Jen Simmons recently posted about it, with an example:

span {
     -moz-text-fill-color: #fde;
  


Text Stroke: Stuck In The Middle With You originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
There is a non-standard way to stroke HTML text (SVG has a standard way). It’s not particularly new. There are -webkit- and -moz- prefixes for it. Jen Simmons recently posted about it, with an example:

span {
     -moz-text-fill-color: #fde;
  -webkit-text-fill-color: #fde;
     -moz-text-stroke-color: #666;
  -webkit-text-stroke-color: #666;
     -moz-text-stroke-width: 2px;  
  -webkit-text-stroke-width: 2px;
}

And she’s right:

This CSS isn’t fully-baked or fully-supported. But it’s good enough to be used today, especially since it’s simply offering a visual enhancement. It’s not mission critical to making a website usable.

I’d only perhaps add that if you were going to do something like add a stroke around white text, you could wrap it in a @supports to be extra sure it’ll be OK (just in case a browser exists that supports text-fill-color but not text-stroke-color) :

@supports 
  ((-webkit-text-stroke-color: #666)
  and
  (-webkit-text-fill-color: white))
  or
  ((-moz-text-stroke-color: #666)
  and
  (-moz-text-fill-color: white)) {
  span {
       -moz-text-fill-color: white;
    -webkit-text-fill-color: white;
       -moz-text-stroke-color: #666;
    -webkit-text-stroke-color: #666;
       -moz-text-stroke-width: 2px;  
    -webkit-text-stroke-width: 2px;
  }
}

See the Pen Text stroke in action by Chris Coyier (@chriscoyier) on CodePen.

It Ruins Most Typefaces

That’s the thing that gets me about it. When you set a stroke straddled over the designed edge of a character, you’re losing the integrity of the shape.

And that’s the trouble with text-stroke in CSS: you have no choice. It’s center-aligned stroke only. Either of the other options, arguably, would have been more useful. It’s not the world’s biggest deal. The larger the text and the beefier the characters, the easier it is to get away with.

Set Behind Trick

If you’d like to simulate an outside-aligned stroke, James Nowland shows how you can set psuedo-element text behind the original text and still use text-stroke:

See the Pen CSS3 Stroke and Gradient Text by James Nowland (@jnowland) on CodePen.

Update! `paint-order` helps

As I write this update (February 2018), Tobi Reif tells me Firefox Nightly now has a CSS property called paint-order, which can help control the order of what is painted on top of what, stroke or fill (or “markers”, which I admittedly don’t know what are).

.stroke-behind {
  -webkit-text-stroke: 5px red;
  paint-order: stroke fill;
} 

This doesn’t help us actually set outside strokes, but it fakes it pretty well. No word on inside set strokes.


Text Stroke: Stuck In The Middle With You originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
https://css-tricks.com/text-stroke-stuck-middle/feed/ 11 251936
outline https://css-tricks.com/almanac/properties/o/outline/ https://css-tricks.com/almanac/properties/o/outline/#comments Tue, 06 Sep 2011 03:53:01 +0000 http://css-tricks.com/?page_id=14079 The outline property in CSS draws a line around the outside of an element. It’s similar to border except that:

  1. It always goes around all the sides, you can’t specify particular sides
  2. It’s not a part of the box model


outline originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
The outline property in CSS draws a line around the outside of an element. It’s similar to border except that:

  1. It always goes around all the sides, you can’t specify particular sides
  2. It’s not a part of the box model, so it won’t affect the position of the element or adjacent elements (nice for debugging!)

Other minor facts include that it doesn’t respect border-radius (makes sense I suppose as it’s not a border) and that it isn’t always rectangular. If the outline goes around an inline element with different font-sizes, for instance, Opera will draw a staggered box around it all.

It is often used for accessibility reasons, to emphasize a link when tabbed to without affecting positioning and in a different way than hover.

a:focus {
  outline: 1px dashed red;
}

Shorthand

outline: [ <outline-width> || <outline-style> || <outline-color> ] | inherit

It takes the same properties as border, but with “outline-” instead.

The above shorthand could have been written:

a:focus {
  outline-width: 1px;
  outline-style: dashed;
  outline-color: red;
}

Notes

  • You can’t set an outline on just one (or two, or three) sides of an elements. All sides only. There is no such thing as outline-top, outline-right, outline-bottom, or outline-left like there is with border.
  • Try opening up the console on any website and running document.head.insertAdjacentHTML("beforeend", "<style>* { outline: 1px solid red; }</style>"); – you’ll see a lot of the sites structure that way.
  • outline is used for :focus styles by default. Remember if you ever remove outline styles, like a:focus { outline: 0; }, you need to add them back in using some other kind of visually distinct style.

More Info

Browser Support

ChromeSafariFirefoxOperaIEAndroidiOS
Any1.2+1.5+7+8+Any3.1+

outline originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
https://css-tricks.com/almanac/properties/o/outline/feed/ 17 14079
Adding Stroke to Web Text https://css-tricks.com/adding-stroke-to-web-text/ https://css-tricks.com/adding-stroke-to-web-text/#comments Sun, 12 Sep 2010 21:12:45 +0000 http://css-tricks.com/?p=7405 Fonts on the web are essentially vector-based graphics. That’s why you can display them at 12px or 120px and they remain crisp and relatively sharp-edged. Vector means that their shape is determined by points and mathematics to describe the shape, …


Adding Stroke to Web Text originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
Fonts on the web are essentially vector-based graphics. That’s why you can display them at 12px or 120px and they remain crisp and relatively sharp-edged. Vector means that their shape is determined by points and mathematics to describe the shape, rather than actual pixel data. Because they are vector, it would make sense if we could do things that other vector programs (e.g. Adobe Illustrator) can do with vector text, like draw a stroke around the individual characters. Well, we can! Example:

h1 {
  /* Prefix required. Even Firefox only supports the -webkit- prefix */
  -webkit-text-stroke-width: 1px;
  -webkit-text-stroke-color: black;
}

Or shorthand:

h1 {
  -webkit-text-stroke: 1px black;
}

You might be thinking “Cool, but if only some browsers support this, if I set my text color to white and my background is white, the stroke makes it look cool in supporting browsers but entirely disappears in non-supporting browsers!”

One possibility is this:

h1 {
  color: black;
  -webkit-text-fill-color: white; /* Will override color (regardless of order) */
  -webkit-text-stroke-width: 1px;
  -webkit-text-stroke-color: black;
}

Shown here with @font-face font Anime Ace 2 by Nate Piekos:

Properly stroked!
Fallback to solid color. Shown here in Firefox

Another possibility is only applying when supported:

@supports (-webkit-text-stroke: 1px black) {
  h1 {
    -webkit-text-stroke: 1px black;
    -webkit-text-fill-color: white;
  }
}

Support

This browser support data is from Caniuse, which has more detail. A number indicates that browser supports the feature at that version and up.

Desktop

ChromeFirefoxIEEdgeSafari
4*49*No15*3.1*

Mobile / Tablet

Android ChromeAndroid FirefoxAndroidiOS Safari
108*107*2.1*4.0-4.1*

Simulation

We can take this a bit further by not relying on the WebKit proprietary entirely. We can use the text-shadow property (supported in Firefox, Opera, and IE 10 as well) and simulate a stroke. We’ll use four shadows, each 1px offset of black with no spread, one each to the top right, top left, bottom left, and bottom right. We’ll remove the WebKit proprietary -webkit-text-fill-color in favor of color since we’re cross-browser compatible now. The only holdout would be IE9 and down, which of course you can use IE-specific stylesheets to account for.

h1 {
  color: white;
  text-shadow:
   -1px -1px 0 #000,  
    1px -1px 0 #000,
    -1px 1px 0 #000,
     1px 1px 0 #000;
}
This is a stroke using all text-shadow. Pretty close to just as good as a real stroke. The primary issue is that you can only get 1px of stroke this way. Any more, and you see gaps. Any more with WebKit text stroke and there is issues too though, so it’s kind of a horse apiece.

Combining

Using both a stroke and a shadow can be a great effect. Let’s toss on a WebKit stroke, the all-around text-shadow stroke, as well as a deeper text-shadow stroke.

h1 {
   -webkit-text-stroke: 1px black;
   color: white;
   text-shadow:
       3px 3px 0 #000,
     -1px -1px 0 #000,  
      1px -1px 0 #000,
      -1px 1px 0 #000,
       1px 1px 0 #000;
}
Lookin’ good

Demo

Alignment

If you are familiar with Adobe Illustrator, you may know that you can align a stroke on the inside of a shape, outside, or centered. That option looks like this in the palette:

From left to right: center, inside, outside

For reasons unbeknownst to me, text in Illustrator can only be set to center stroke alignment as well. Once you expand the text into regular vector paths though, all three options become available. Reminder from Sam Frysteen: add a new stroke in the Appearance panel and move it below your text (basically mimics outside stroke alignment).

From top to bottom: inside, centered, outside.

Only outside text stroke alignment looks any good at all to me. It’s unfortunate, both for CSS and for Illustrator, that the unchangeable default is centered. The solution is just not to go too crazy with the thickness of your stroke border and things should be OK. Note: the text-shadow-only solution doesn’t have this problem, but also is unable to stroke any more than 1px.

If you use a pseudo element, you can stroke the same text behind the original text and kinda fake outside stroke.

We have a whole article on this alignment issue: Text Stroke: Stuck In The Middle With You. A minor bit of good news, the paint-order property allows you to esssentially have outside set strokes, once more browsers support it.

What we can’t do

There are other things that vector-based graphics programs can do with text. You can squish the letter horizontally / stretch them vertically. This type of text treatment is almost universally frowned upon, so no big loss that we can’t do that. You can also set type on an irregular line (like around a circle). It certainly would be cool to do this with web text. Perhaps we could set text to follow the border path of its parent element.

p.circular {
  width: 200px;
  height: 200px;
  border-radius: 100px;
  
  /* NOT REAL */
  text-align: border-path;
}

In Illustrator, we can also tell a stroke how to handle sharp corners: rounded, beveled, or mitered. These can have nice effects, are not possible on the web. However, the WebKit handling of corners is pretty nice at its default (whatever it is), and arguably nicer than any of the options in Illustrator.

Fancies

For the record, you can use any type of color value for the color of stroke (hex, rgba, hsla, keyword). That means transparent strokes if you want them, which indeed “stack” in that if strokes overlap each other (common) they will be darker.

As far as the keyframe animation, the stroke color will animate but the stroke width will not (weird).

/* Only the color will change, not the width */
@keyframes colorchange {
  0% {
    -webkit-text-stroke: 10px red;
  }
  100% {
    -webkit-text-stroke: 20px green;
  }
}

More information


Adding Stroke to Web Text originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
https://css-tricks.com/adding-stroke-to-web-text/feed/ 38 7405