Tillitsdone
down Scroll to discover

Mastering CSS text-emphasis for Enhanced Typography

Learn how to use CSS text-emphasis to add emphasis marks to text.

Discover various options for customizing style and color to enhance your web designs.
thumbnail

Introduction to CSS text-emphasis

The text-emphasis property in CSS is a handy tool for adding emphasis marks to text. Unlike text-decoration, which applies styles like underlines across entire elements, text-emphasis focuses on individual characters, excluding spaces and control characters. It’s a shorthand for text-emphasis-style and text-emphasis-color, making it easy to customize emphasis marks.

By default, emphasis marks are about 50% the size of the font and can affect line height if there isn’t enough space for them. text-emphasis is great for creating visually appealing and meaningful typography.

Differences Between text-emphasis and text-decoration

While both properties add visual effects to text, they have key differences:

Inheritance and Scope:

  • text-emphasis: Inherits from parent elements, affecting child elements.
  • text-decoration: Does not inherit. Stays within the element it’s applied to.

Application:

  • text-emphasis: Applies to individual characters.
  • text-decoration: Applies to the entire element.

Line Height:

  • text-emphasis: Emphasis marks are about 50% of the font size and may affect line height.
  • text-decoration: Typically doesn’t affect line height unless very thick decorations are used.

Inheritance and Effects on Line Height

Inheritance:

  • text-emphasis: Inherits from parent elements, making styling more dynamic and consistent.

Effects on Line Height:

  • Size of Emphasis Symbols: About 50% of the font size.
  • Line Height Adjustments: May require adjusting line height to prevent overlapping text.

Best Practices:

  • Consider Font Size: Larger fonts and symbols may need more vertical space.
  • Adjust Line Height: Use the line-height property to ensure readability.

Note on text-emphasis-position

The text-emphasis property does not reset the value of text-emphasis-position. This property defines the position of the emphasis marks (e.g., above or below the text). Since the position rarely changes within a text block, text-emphasis doesn’t include it by default.

Usage of text-emphasis-position:

  • When to Use: Use separately when you need to change the position of emphasis marks.
  • Common Values: over, under, right, left.

Example:

/* Apply emphasis marks above the text */
p {
text-emphasis: filled circle;
text-emphasis-position: over;
}

Constituent Properties of text-emphasis

The text-emphasis property is a shorthand for:

1. text-emphasis-style:

  • Defines the shape and style of the emphasis marks.
  • Possible Values: none, filled, open, dot, circle, double-circle, triangle, sesame, <string>.

2. text-emphasis-color:

  • Defines the color of the emphasis marks.
  • Possible Values: <color> (default is currentcolor).

Example:

/* Apply filled triangle marks with a specific color */
p {
text-emphasis-style: filled triangle;
text-emphasis-color: #d55;
}

Combining Both Properties:

/* Apply filled double-circle marks with a green color */
h2 {
text-emphasis: filled double-circle green;
}

Syntax and Values of text-emphasis

Syntax:

text-emphasis: [<text-emphasis-style> || <text-emphasis-color>];

Values:

1. Initial Value:

text-emphasis: none; /* No emphasis marks */

2. String Value:

text-emphasis: "x";
text-emphasis: "点";
text-emphasis: "\25B2"; /* Unicode for triangle */
text-emphasis: "*" #555; /* Combining string with color */

3. Keywords Value:

text-emphasis: filled; /* Solid color fill */
text-emphasis: open; /* Hollow shape */
text-emphasis: filled sesame; /* Filled sesame shape */
text-emphasis: open sesame; /* Open sesame shape */

4. Keywords Value Combined with a Color:

text-emphasis: filled sesame #555; /* Combining style and color */

5. Global Values:

text-emphasis: inherit;
text-emphasis: initial;
text-emphasis: revert;
text-emphasis: revert-layer;
text-emphasis: unset;

Specific Values:

  • none: No emphasis marks.
  • filled: Solid color fill.
  • open: Hollow shape.
  • dot: Small circles.
  • circle: Large circles.
  • double-circle: Double circles.
  • triangle: Triangles.
  • sesame: Sesames.
  • <string>: Custom string.
  • <color>: Color of the mark.

Examples of text-emphasis Usage

To effectively use the text-emphasis property in your web designs, it’s helpful to see practical examples. These examples demonstrate how to apply emphasis marks to text elements, customizing both the style and the color to achieve various visual effects.

Example 1: Applying Filled Triangle Marks

In this example, we’ll apply filled triangle marks to a heading element, using a specific color to highlight each character.

HTML:

<h2>This is important!</h2>

CSS:

h2 {
text-emphasis: filled triangle #d55;
}

Result: The heading “This is important!” will have filled triangle marks next to each character, with the color #d55.

Example 2: Applying Open Circle Marks

In this example, we’ll apply open circle marks to a paragraph element, using a custom color.

HTML:

<p>This paragraph has open circle marks as emphasis.</p>

CSS:

p {
text-emphasis: open circle blue;
}

Result: The paragraph will have open circle marks next to each character, with the color blue.

Example 3: Using a Custom String as Emphasis Marks

In this example, we’ll use a custom string as the emphasis mark for a span element, setting a specific color.

HTML:

<span>Custom string emphasis marks</span>

CSS:

span {
text-emphasis: "*" red;
}

Result: The text within the span will have asterisks as emphasis marks, with the color red.

Example 4: Combining Style and Color

In this example, we’ll combine text-emphasis-style and text-emphasis-color to create a unique emphasis effect on a heading element.

HTML:

<h3>Combining Style and Color</h3>

CSS:

h3 {
text-emphasis: filled sesame purple;
}

Result: The heading “Combining Style and Color” will have filled sesame marks next to each character, with the color purple.

Example 5: Applying Emphasis Marks to Multiple Elements

In this example, we’ll apply emphasis marks to multiple elements within a container, demonstrating the inheritance behavior of the text-emphasis property.

HTML:

<div class="emphasis-container">
<h4>Heading with Emphasis</h4>
<p>Paragraph with the same emphasis marks.</p>
</div>

CSS:

.emphasis-container {
text-emphasis: filled double-circle green;
}

Result: Both the heading and the paragraph within the container will inherit the filled double-circle marks with the color green.

Formal Definition and Syntax

Understanding the formal definition and syntax of the text-emphasis property is crucial for effectively implementing it in your web designs. The text-emphasis property is a shorthand for text-emphasis-style and text-emphasis-color, allowing you to easily apply and customize emphasis marks to your text.

Initial Value:

  • The initial value for text-emphasis is none for text-emphasis-style and currentcolor for text-emphasis-color.

Applies To:

  • The text-emphasis property applies to all elements.

Inherited:

  • Yes, the text-emphasis property is inherited, meaning that emphasis marks applied to a parent element will also be applied to its child elements.

Computed Value:

  • The computed value for text-emphasis is as specified for each of its constituent properties: text-emphasis-style as specified and text-emphasis-color as a computed color.

Animation Type:

  • The animation type for text-emphasis-color is a color, and for text-emphasis-style, it is discrete.

Formal Syntax:

text-emphasis = [<'text-emphasis-style'> || <'text-emphasis-color'>];
<text-emphasis-style> =
none |
[filled | open] ||
[dot | circle | double-circle | triangle | sesame] |
<string>;
<text-emphasis-color> = <color>;

Explanation:

  • <text-emphasis-style>: Specifies the style of the emphasis marks. It can be none, filled, open, or specific shapes like dot, circle, double-circle, triangle, and sesame. It also accepts a string value for custom marks.
  • <text-emphasis-color>: Specifies the color of the emphasis marks. It accepts any valid CSS color value.

Browser Compatibility and Specifications

Understanding the browser compatibility and specifications of the text-emphasis property is crucial for ensuring that your web designs are consistent and functional across different platforms and devices.

Browser Compatibility:

The text-emphasis property is supported by most modern web browsers, but it’s important to check the specific versions to ensure compatibility. Here is a summary of the browser support for text-emphasis:

  • Google Chrome: Supported from version 25 and above.
  • Microsoft Edge: Supported from version 79 and above.
  • Mozilla Firefox: Supported from version 46 and above.
  • Opera: Supported from version 15 and above.
  • Safari: Supported from version 7 and above.

Note: While the text-emphasis property is widely supported, some older browser versions may not fully support all features or may require vendor prefixes for proper rendering. It’s always a good practice to test your web designs across different browsers and versions to ensure compatibility.

Specifications:

The text-emphasis property is defined in the CSS Text Decoration Module Level 3 specification. This specification outlines the details and behavior of the text-emphasis property, including its syntax, values, and interactions with other CSS properties.

Key Points from the Specification:

  • Property Definition: The text-emphasis property is a shorthand for text-emphasis-style and text-emphasis-color, allowing you to set both the style and color of emphasis marks in a single declaration.
  • Initial Values: The initial value for text-emphasis-style is none, and for text-emphasis-color, it is currentcolor.
  • Inheritance: The text-emphasis property inherits, meaning that emphasis marks applied to a parent element will also be applied to its child elements.
  • Computed Value: The computed value for text-emphasis is as specified for each of its constituent properties: text-emphasis-style as specified and text-emphasis-color as a computed color.
  • Animation Type: The animation type for text-emphasis-color is a color, and for text-emphasis-style, it is discrete.

Example of Browser Compatibility Check:

To ensure that your web designs are compatible with different browsers, you can use feature detection or browser-specific prefixes. Here is an example of how to use a vendor prefix for the text-emphasis property:

h2 {
text-emphasis: filled double-circle green;
-webkit-text-emphasis: filled double-circle green; /* For older WebKit-based browsers */
}

In this example, the -webkit-text-emphasis prefix is used to ensure compatibility with older WebKit-based browsers that may not fully support the text-emphasis property without the prefix.

Related Properties and See Also

To fully utilize the text-emphasis property in your web designs, it’s important to be aware of related properties and resources that can help you create visually appealing and functional web content. Here are some related properties and additional resources to explore:

Related Properties:

  1. text-emphasis-style:
    • This property defines the shape and style of the emphasis marks. It is one of the constituent properties of text-emphasis. You can use it to set specific shapes like dot, circle, triangle, and more, as well as specify whether the marks are filled or open.
    h2 {
    text-emphasis-style: filled triangle;
    }
  2. text-emphasis-color:
    • This property defines the color of the emphasis marks. It is the other constituent property of text-emphasis. You can use it to set a specific color for the emphasis marks, allowing you to customize their appearance to match your design scheme.
    p {
    text-emphasis-color: #555;
    }
  3. text-emphasis-position:
    • This property allows you to define the position of the emphasis marks relative to the text. While text-emphasis does not reset this property, you can use text-emphasis-position to explicitly set the position of the marks above, below, to the right, or to the left of the text.
    h3 {
    text-emphasis: filled circle;
    text-emphasis-position: over;
    }

See Also:

  1. CSS Text Decoration Module Level 3:
    • This specification provides detailed information about text decoration and emphasis properties, including text-emphasis. It is a valuable resource for understanding the behavior and syntax of these properties.
    • [CSS Text Decoration Module Level 3]WebsiteUrl
  2. CSS Color Module Level 3:
    • This specification defines the color values and syntax used in CSS, which is relevant for setting the text-emphasis-color property. It covers the various color values and how they can be used in CSS.
    • [CSS Color Module Level 3]WebsiteUrl
  3. MDN Web Docs:
    • The Mozilla Developer Network (MDN) provides comprehensive documentation on CSS properties, including detailed explanations, examples, and browser compatibility information. It is an excellent resource for learning about and using the text-emphasis property and related properties.
    • [MDN Web Docs - text-emphasis]WebsiteUrl
  4. Can I Use:
    • This website offers detailed browser compatibility information for various CSS properties, including text-emphasis. It is a useful tool for checking which browsers support the property and any specific notes or known issues.
    • [Can I Use - text-emphasis]WebsiteUrl

Practical Tips:

  • Always test your web designs on different browsers and versions to ensure compatibility.
  • Use vendor prefixes when needed to support older browser versions.
  • Refer to the official specifications and documentation for detailed information and best practices.

By understanding and utilizing these resources, you can create visually appealing and functional web designs that make the most of the text-emphasis property.

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.