Tillitsdone
down Scroll to discover

CSS outline-color Enhancing Element Visibility

Learn about the CSS outline-color property, which enhances element visibility by setting the outline color.

Discover available options like color names, hex, RGB, and more.
thumbnail

Introduction

The outline-color property in CSS sets the color of an element’s outline, making the element more visible and focused. An outline is a line drawn around an element, outside its border, and can overlap other content. Customizing the outline-color can greatly improve user experience and accessibility.

Syntax

The outline-color property specifies the color of an element’s outline. Here’s the basic syntax:

outline-color: <color> | inherit;

Values

  • <color>: Sets the outline color to any valid CSS color (names, hexadecimal values, RGB, RGBA, HSL, HSLA).
  • inherit: Sets the outline color to the same value as the parent element.

Examples

/* Setting the outline color to a specific color */
outline-color: #f92525;
outline-color: rgb(30, 222, 121);
outline-color: blue;
/* Inheriting the outline color from the parent element */
outline-color: inherit;

Description

An outline is a line drawn around an element, outside its border. Unlike borders, outlines don’t affect the layout and can overlap other content. The outline-color property is often used with the outline shorthand property to define an outline’s appearance, making it easier to create custom focus styles for better accessibility.

Key Points

  • Outline vs. Border: Outlines are drawn outside the element’s border and don’t affect the layout. Borders are part of the element’s box model and can impact the layout.
  • Accessibility: Custom focus styles often involve adjusting the outline property. Ensuring good color contrast is crucial for users with low vision.
  • Shorthand Property: Using the outline shorthand property can set width, style, and color in one declaration.

Accessibility

Accessibility is crucial for making your content usable by everyone. The outline-color property helps create more accessible web designs.

Custom Focus Styles

Custom focus styles involve adjusting the outline property. When changing the outline color, ensure a high contrast ratio with the background.

Contrast Ratio

To meet Web Content Accessibility Guidelines (WCAG), aim for a contrast ratio of 4.5:1 for normal text and 3:1 for larger text (18.66px and bold or larger, or 24px or larger).

Tools and Resources

Formal Definition

The outline-color property sets the color of an element’s outline, part of the CSS Outline Module, and is supported by all major browsers.

Initial Value

  • Initial Value: auto

Applies To

  • Applies To: All elements

Inherited

  • Inherited: No

Computed Value

  • Computed Value: For auto, it’s currentcolor. For color values, it’s the corresponding rgb() or rgba() value.

Animation Type

  • Animation Type: Color (animated as a color value)

Formal Syntax

outline-color =
auto |
<color> |
[<length-percentage> | <flex>]?
<length-percentage> =
<length> |
<percentage>

Examples

Setting a Solid Blue Outline

<!DOCTYPE html>
<html>
<head>
<title>Solid Blue Outline Example</title>
<style>
p {
outline: 2px solid; /* Set the outline width and style */
outline-color: #0000ff; /* Make the outline blue */
margin: 5px;
}
</style>
</head>
<body>
<p>My outline is blue, as you can see.</p>
</body>
</html>

Setting an Outline with a Specific Hexadecimal Color

<!DOCTYPE html>
<html>
<head>
<title>CSS outline-color Example</title>
<style>
div {
outline: 2px solid; /* Set the outline width and style */
outline-color: #ff00ff; /* Make the outline magenta */
margin: 5px;
padding: 10px;
}
</style>
</head>
<body>
<div>My outline is magenta, as you can see.</div>
</body>
</html>

Setting an Outline with an RGB Color

<!DOCTYPE html>
<html>
<head>
<title>CSS outline-color Example</title>
<style>
span {
outline: 2px solid; /* Set the outline width and style */
outline-color: rgb(0, 255, 0); /* Make the outline green */
margin: 5px;
padding: 10px;
}
</style>
</head>
<body>
<span>My outline is green, as you can see.</span>
</body>
</html>

Setting an Outline with an HSL Color

<!DOCTYPE html>
<html>
<head>
<title>CSS outline-color Example</title>
<style>
h1 {
outline: 2px solid; /* Set the outline width and style */
outline-color: hsl(120, 100%, 50%); /* Make the outline green */
margin: 5px;
padding: 10px;
}
</style>
</head>
<body>
<h1>My outline is green, as you can see.</h1>
</body>
</html>

Setting an Outline with a Transparent Color

<!DOCTYPE html>
<html>
<head>
<title>CSS outline-color Example</title>
<style>
button {
outline: 2px solid; /* Set the outline width and style */
outline-color: rgba(255, 0, 0, 0.5); /* Make the outline semi-transparent red */
margin: 5px;
padding: 10px;
}
</style>
</head>
<body>
<button>My outline is semi-transparent red, as you can see.</button>
</body>
</html>

Setting an Outline with Inherited Color

<!DOCTYPE html>
<html>
<head>
<title>CSS outline-color Example</title>
<style>
body {
outline-color: red; /* Set the outline color for the body */
}
p {
outline: 2px solid; /* Set the outline width and style */
outline-color: inherit; /* Inherit the outline color from the body */
margin: 5px;
padding: 10px;
}
</style>
</head>
<body>
<p>My outline color is inherited from the body, as you can see.</p>
</body>
</html>

Specifications

The outline-color property is defined in the CSS Basic User Interface Module Level 4. This module specifies how user interface elements are styled, including outlines.

CSS Basic User Interface Module Level 4

  • Specification: CSS Basic User Interface Module Level 4
  • Description: This specification outlines the behavior and syntax for the outline-color property, including its values, initial settings, and how it interacts with other CSS properties.

Browser Compatibility

The outline-color property in CSS is widely supported across major browsers, ensuring that web developers can use it to enhance the visual appeal and accessibility of their designs.

BrowserVersion
Chrome1
Edge12
Firefox1.5
Opera7
Safari1.2

Notes on Compatibility

  • Consistent Support: The outline-color property has been consistently supported across all major browsers for many years, making it a reliable choice for web developers.
  • Future-Proof: Given its long-standing support, using the outline-color property ensures that your designs will be compatible with both current and future browser versions.

Additional Resources

For more detailed information on browser compatibility, you can refer to resources such as:

  • Can I use…: A comprehensive database that provides up-to-date browser support tables for front-end web technologies.
  • MDN Web Docs: The Mozilla Developer Network offers extensive documentation and compatibility information for CSS properties, including outline-color.

See Also

To further enhance your understanding and usage of the outline-color property in CSS, you might find the following resources and related properties useful:

Related CSS Properties

  • [outline]WebsiteUrl: A shorthand property for setting the outline width, style, and color in a single declaration.
  • [outline-width]WebsiteUrl: Specifies the width of an element’s outline.
  • [outline-style]WebsiteUrl: Defines the style of an element’s outline, such as solid, dotted, or dashed.
  • [outline-offset]WebsiteUrl: Sets the space between the outline and the element’s border.

Color-Related Properties

  • [color]WebsiteUrl: Sets the foreground color of an element’s text.
  • [background-color]WebsiteUrl: Specifies the background color of an element.
  • [border-color]WebsiteUrl: Sets the color of an element’s border.
  • [text-decoration-color]WebsiteUrl: Defines the color of text decorations like underlines.
  • [text-emphasis-color]WebsiteUrl: Sets the color of emphasis marks.
  • [text-shadow]WebsiteUrl: Adds shadow effects to text.
  • [caret-color]WebsiteUrl: Specifies the color of the text input caret.
  • [column-rule-color]WebsiteUrl: Sets the color of the rule between columns.

Tutorials and Guides

  • [CSS Outlines Tutorial]WebsiteUrl: A detailed guide on using outlines in CSS, including practical examples and best practices.
  • [HTML Reference Guide]WebsiteUrl: A comprehensive resource for understanding HTML elements and attributes.

Web Accessibility

These resources and related properties will help you gain a deeper understanding of the outline-color property and its role in creating visually appealing and accessible web designs.

icons/css-4.svg CSS Blogs
CSS3 is the latest version of Cascading Style Sheets, offering advanced styling features like animations, transitions, shadows, gradients, and responsive design.
icons/logo-tid.svg

Talk with CEO

Ready to bring your web/app to life or boost your team with expert Thai developers?
Contact us today to discuss your needs, and let’s create tailored solutions to achieve your goals. We’re here to help at every step!
🖐️ Contact us
Let's keep in Touch
Thank you for your interest in Tillitsdone! Whether you have a question about our services, want to discuss a potential project, or simply want to say hello, we're here and ready to assist you.
We'll be right here with you every step of the way.
Contact Information
rick@tillitsdone.com+66824564755
Find All the Ways to Get in Touch with Tillitsdone - We're Just a Click, Call, or Message Away. We'll Be Right Here, Ready to Respond and Start a Conversation About Your Needs.
Address
9 Phahonyothin Rd, Khlong Nueng, Khlong Luang District, Pathum Thani, Bangkok Thailand
Visit Tillitsdone at Our Physical Location - We'd Love to Welcome You to Our Creative Space. We'll Be Right Here, Ready to Show You Around and Discuss Your Ideas in Person.
Social media
Connect with Tillitsdone on Various Social Platforms - Stay Updated and Engage with Our Latest Projects and Insights. We'll Be Right Here, Sharing Our Journey and Ready to Interact with You.
We anticipate your communication and look forward to discussing how we can contribute to your business's success.
We'll be here, prepared to commence this promising collaboration.
Frequently Asked Questions
Explore frequently asked questions about our products and services.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.