Ora

How to set tick mark in HTML?

Published in HTML Symbols 4 mins read

To display a tick mark (✓) in HTML, you can use various methods, primarily involving HTML entities, Unicode character codes, or CSS. These methods ensure the check mark symbol is rendered consistently across different browsers and devices.

Displaying a Check Mark Symbol in HTML

A "tick mark" in the context of HTML typically refers to the universally recognized check mark symbol (✓). Here are the primary ways to embed this symbol directly into your web pages.

1. Using HTML Entities

HTML entities are special sequences of characters that represent reserved characters or symbols not easily typed on a standard keyboard. They are often the most straightforward way to include common symbols like the check mark.

  • Named Entity: ✓
    • This is easy to remember and type.
    • Example: <span>&check; Item completed</span>
  • Decimal Numeric Entity: &#10003;
    • This refers to the decimal value of the Unicode character.
    • Example: <p>&#10003; Task done</p>

Using HTML entities is generally recommended for its readability and simplicity when placing symbols directly in your HTML content.

2. Using Unicode Character Codes (Hexadecimal)

Unicode provides a unique number for every character, no matter what platform, program, or language. You can use the hexadecimal representation of the Unicode character in HTML.

  • Hexadecimal Numeric Entity: &#x2713;
    • The x indicates that the following numbers are in hexadecimal format. The Unicode for the check mark is U+02713.
    • Example: <li>&#x2713; Feature enabled</li>

This method is functionally equivalent to the decimal numeric entity and is often used by developers familiar with Unicode hexadecimal representations.

3. Using CSS ::before or ::after Pseudo-elements

For styling purposes or when adding decorative elements that aren't part of the document's core content, CSS pseudo-elements are an excellent choice. This method uses the Unicode value in the content property of CSS.

  • The Unicode U+02713 is represented as \2713 in CSS content property.

    • Example:

      <style>
        .checked-item::before {
          content: "\2713"; /* Unicode character for check mark */
          margin-right: 5px;
          color: green;
        }
      </style>
      <p class="checked-item">This item is checked.</p>

      This approach keeps your HTML cleaner and separates content from presentation. You can easily style the check mark (color, size, position) using CSS properties. Learn more about CSS pseudo-elements.

4. Combining HTML Elements for Styling

You can wrap the HTML entities or Unicode characters within semantic HTML elements like <span>, <i>, or <b> to apply specific styling.

  • Example with <span>:

    <style>
      .custom-check {
        color: blue;
        font-weight: bold;
        font-size: 1.2em;
      }
    </style>
    <p><span class="custom-check">&check;</span> All good!</p>
    <p><i>&#10003;</i> Completed successfully.</p>

    This allows for granular control over the appearance of the check mark without affecting the surrounding text.

Summary of Check Mark Codes

Here's a quick reference table for the check mark symbol (✓):

Description Code Example (HTML) Example (CSS content)
Unicode U+02713 N/A "\2713"
HTML Entity (Named) &check; &check; N/A
HTML Entity (Decimal) &#10003; &#10003; N/A
HTML Entity (Hex) &#x2713; &#x2713; N/A

When to Use Each Method

Choosing the right method depends on your specific needs:

  • For direct content: Use &check; or &#10003; within your HTML for simplicity and readability, especially if the symbol is an integral part of the text.
  • For styling or decorative purposes: Use the CSS ::before or ::after pseudo-elements with content: "\2713";. This approach is ideal for lists, status indicators, or any scenario where the check mark is a visual cue rather than textual content.
  • When consistency is paramount: All methods are generally consistent, but using &#x2713; or the CSS Unicode escape ensures you're directly referencing the Unicode character.

Styling Your Check Mark

Once embedded, you can style your check mark just like any other text or element using CSS.

  • Color: color: green;
  • Size: font-size: 1.5em;
  • Weight: font-weight: bold;
  • Position: margin, padding, position: absolute; (especially with pseudo-elements).

For instance, to make a check mark stand out:

.highlighted-check {
  color: #008000; /* Dark green */
  font-size: 1.3em;
  line-height: 1; /* Adjust vertical alignment if needed */
  margin-right: 0.2em;
}

Then in your HTML: <span class="highlighted-check">&#10003;</span> Item verified

By using these methods, you can effectively integrate the check mark symbol into your HTML documents, enhancing both functionality and visual appeal.