Tillitsdone
down Scroll to discover
CSS Appearance Customize UI Elements for Native Look
Learn how to use the CSS appearance property to customize UI elements like buttons and checkboxes for a native look.

Explore standard, compatibility, and non-standard values.
thumbnail

Introduction to CSS Appearance

The appearance CSS property is a powerful tool for web developers, allowing them to style UI elements to match the user’s operating system theme. This ensures that buttons, checkboxes, and other widgets have a native look and feel, enhancing user experience.

Before it was standardized, the appearance property was used to make elements look like platform-specific widgets, but this led to inconsistencies. Now, developers are encouraged to use standard keywords to maintain consistency across modern browsers.

If you plan to use the appearance property, thorough testing is essential. While it is supported in most modern browsers, there can be differences in how it works. Older browsers might not support all features, and even the none keyword doesn’t always have the same effect on all form elements across different browsers. However, these differences are smaller in the newest browsers.

By understanding and using the appearance property, you can create more cohesive and user-friendly interfaces that look great and work well across a wide range of devices and browsers.

Baseline Compatibility

The appearance CSS property is widely supported and has been available across many devices and browsers since March 2022. It allows developers to use platform-specific styling for UI elements like buttons and checkboxes, making interfaces more user-friendly.

However, its implementation can vary across different browsers and versions, so thorough testing is recommended to ensure consistent behavior.

By understanding the baseline compatibility of the appearance property, developers can create more robust and consistent web designs that work seamlessly across various devices and browsers.

Historical Context and Misfeatures

Before the appearance CSS property was standardized, it was used to make elements look like platform-specific widgets, such as buttons or checkboxes. This allowed developers to create interfaces that matched the user’s operating system. However, this usage led to inconsistencies and limited control over the appearance of these widgets.

Authors were encouraged to use standard keywords to maintain consistency and compatibility across different browsers. For example, the none keyword, which removes certain features of widgets like the arrow in a select element, didn’t work the same way across all form elements in different browsers. Some older browsers didn’t support this keyword at all, leading to inconsistent behavior.

As web development practices evolved, the need for a more standardized approach became evident. The appearance property was refined to provide better control over the styling of UI elements, ensuring that developers could create consistent and user-friendly interfaces across various platforms.

By understanding the historical context and misfeatures of the appearance property, web developers can avoid common pitfalls and use this powerful tool more effectively. This knowledge helps in creating more robust and visually appealing web designs that align with modern web development best practices.

CSS Appearance Syntax

The syntax of the appearance CSS property is straightforward and allows developers to control the styling of UI elements easily. The property can take various values, including standard keywords and global values.

/* Standard values */
appearance: none;
appearance: auto;
appearance: menulist-button;
appearance: textfield;
/* Global values */
appearance: inherit;
appearance: initial;
appearance: revert;
appearance: revert-layer;
appearance: unset;
/* Compatibility values */
appearance: button;
appearance: checkbox;

Each keyword has a specific purpose and allows developers to apply platform-specific styling to elements. For instance, the none keyword hides certain features of widgets, while the auto keyword acts as none on elements with no special styling.

Key Values and Their Uses

  • none: Hides certain features of widgets, such as the arrow in a select element.
  • auto: Acts as none on elements with no special styling.
  • menulist-button: Applies platform-specific styling to menu list buttons.
  • textfield: Applies platform-specific styling to text fields.

Global Values

  • inherit: Inherits the value from the parent element.
  • initial: Sets the property to its default value.
  • revert: Reverts the property to the browser’s default styling.
  • revert-layer: Reverts the property to the default styling for the current cascade layer.
  • unset: Resets the property to its natural value, which might be its initial value or inherited value.

Compatibility Values

The <compat-auto> values provide compatibility with older browsers and include keywords like button, checkbox, listbox, menulist, meter, progress-bar, push-button, radio, searchfield, slider-horizontal, square-button, and textarea. These values are equivalent to auto for maintaining compatibility with older browsers.

By understanding and using the appropriate syntax and values for the appearance property, web developers can ensure that their designs are both functional and visually consistent. This enhances the overall user experience and ensures compatibility across different browsers and devices.

Non-standard Values

Non-standard values are specific to certain browsers and may not work consistently across all platforms. These values are often prefixed with vendor-specific prefixes like -moz- for Mozilla Firefox or -webkit- for WebKit browsers.

Examples of Non-standard Values

  • -moz-appearance for Firefox
    • attachment
    • checkbox-container
    • checkbox-label
    • checkbox-small
    • checkmenuitem
    • color-well
    • progressbar
    • radio-container
    • radio-small
    • scrollbar
    • scrollbarbutton-up
    • scrollbarbutton-down
    • scrollbartrack-horizontal
    • scrollbartrack-vertical
  • -webkit-appearance for WebKit browsers (Safari, Chrome, Edge)
    • button-bevel
    • caret
    • inner-spin-button
    • list-button
    • media-controls-background
    • media-enter-fullscreen-button
    • media-exit-fullscreen-button
    • media-fullscreen-volume-slider
    • media-mute-button
    • media-play-button
    • media-overlay-play-button
    • media-seek-back-button
    • media-seek-forward-button
    • media-slider
    • media-sliderthumb
    • media-volume-slider
    • media-volume-sliderthumb
    • textfield-multiline

Examples of CSS Appearance

The appearance property allows you to customize UI elements. Here are some examples:

Apply Custom Styling

This example shows how to remove default styling from a checkbox and a select element, then apply custom styling.

HTML

<input type="checkbox" />
<input type="checkbox" checked />
<select>
<option>default</option>
<option>option 2</option>
</select>
<select class="none">
<option>appearance: none</option>
<option>option 2</option>
</select>

CSS

input {
appearance: none;
width: 1em;
height: 1em;
display: inline-block;
background: red;
}
input:checked {
border-radius: 50%;
background: green;
}
select {
border: 1px solid black;
font-size: 1em;
}
select.none {
appearance: none;
}

Result

In this example, the checkboxes are styled as red circles when unchecked and green circles when checked. The select element with the class none has the default arrow removed, allowing for custom styling.

Removing Default Styling for Buttons

Sometimes, you might want to remove the default styling of buttons to apply your custom styles. The appearance property can help with this.

HTML

<button class="custom-button">Custom Button</button>

CSS

.custom-button {
appearance: none;
background-color: #007BFF;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
.custom-button:hover {
background-color: #0056b3;
}

Result

This example removes the default styling of the button and applies custom styles. The button has a blue background with white text, and it changes color on hover.

Styling a Text Field

You can also use the appearance property to style text fields to match the native look and feel of the user’s operating system.

HTML

<input type="text" class="custom-textfield" placeholder="Enter text">

CSS

.custom-textfield {
appearance: textfield;
border: 1px solid #ccc;
padding: 10px;
border-radius: 5px;
}

Result

In this example, the text field is styled to match the native appearance of a text field on the user’s operating system, with additional custom styling applied.

Customizing Checkboxes and Select Elements

Here’s how to remove the default styling from a checkbox and select element, and then apply custom styles.

HTML

<input type="checkbox" />
<input type="checkbox" checked />
<select>
<option>default</option>
<option>option 2</option>
</select>
<select class="none">
<option>appearance: none</option>
<option>option 2</option>
</select>

CSS

input {
appearance: none;
width: 1em;
height: 1em;
display: inline-block;
background: red;
}
input:checked {
border-radius: 50%;
background: green;
}
select {
border: 1px solid black;
font-size: 1em;
}
select.none {
appearance: none;
}

Result

In this example, the checkboxes are styled as red circles when unchecked and green circles when checked. The select element with the class none has the default arrow removed, allowing for custom styling.

Summary

The appearance CSS property is a powerful way to customize the look and feel of UI elements based on the user’s operating system theme. It helps create more consistent and user-friendly interfaces. Whether removing default styles or applying custom styles, the appearance property offers the flexibility needed for visually appealing and functional web designs.

Browser Compatibility

The appearance property is widely supported across modern browsers, including:

  • Google Chrome (version 83 onwards)
  • Mozilla Firefox (version 80 onwards)
  • Microsoft Edge (version 83 onwards)
  • Apple Safari (version 15.4 onwards)

For mobile and tablet devices:

  • Android Chrome (version 128 onwards)
  • Android Firefox (version 127 onwards)
  • iOS Safari (version 15.4 onwards)

WebKit Values

The appearance property supports various non-standard values specific to WebKit browsers, providing additional customization options for UI elements.

Common WebKit Values

Here are some commonly used WebKit values for the appearance property:

  • -webkit-appearance: none;
  • -webkit-appearance: button;
  • -webkit-appearance: checkbox;
  • -webkit-appearance: radio;
  • -webkit-appearance: textfield;

Mozilla Values

The appearance CSS property has special values for Mozilla Firefox, prefixed with -moz-appearance. These values help developers style UI elements to match the native look of the user’s operating system.

Common Mozilla Values

Here are some commonly used Mozilla values for the appearance property:

  • button
    • Styles an element as a button.
    -moz-appearance: button;
  • checkbox
    • Styles an element as a checkbox.
    -moz-appearance: checkbox;
  • radio
    • Styles an element as a radio button.
    -moz-appearance: radio;
  • menulist
    • Styles an element as a menu list.
    -moz-appearance: menulist;
  • menulist-button
    • Styles an element as a menu list button.
    -moz-appearance: menulist-button;
  • textfield
    • Styles an element as a text field.
    -moz-appearance: textfield;
  • textarea
    • Styles an element as a text area.
    -moz-appearance: textarea;
  • scrollbar
    • Styles an element as a scrollbar.
    -moz-appearance: scrollbar;
  • scrollbarbutton-up
    • Styles an element as the up button of a scrollbar.
    -moz-appearance: scrollbarbutton-up;
  • scrollbarbutton-down
    • Styles an element as the down button of a scrollbar.
    -moz-appearance: scrollbarbutton-down;
  • scrollbartrack-horizontal
    • Styles an element as the horizontal track of a scrollbar.
    -moz-appearance: scrollbartrack-horizontal;
  • scrollbartrack-vertical
    • Styles an element as the vertical track of a scrollbar.
    -moz-appearance: scrollbartrack-vertical;
  • progressbar
    • Styles an element as a progress bar.
    -moz-appearance: progressbar;
  • meter
    • Styles an element as a meter.
    -moz-appearance: meter;

Example Usage

Here is an example of how to use some of the Mozilla values for the appearance property in your CSS:

HTML

<input type="text" class="textfield" placeholder="Enter text">
<input type="checkbox" class="checkbox">
<input type="radio" class="radio">
<button class="button">Button</button>
<input type="range" class="slider">
<progress value="50" max="100" class="progressbar"></progress>

CSS

.textfield {
-moz-appearance: textfield;
border: 1px solid #ccc;
padding: 10px;
border-radius: 5px;
}
.checkbox {
-moz-appearance: checkbox;
}
.radio {
-moz-appearance: radio;
}
.button {
-moz-appearance: button;
background-color: #007BFF;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
.slider {
-moz-appearance: slider-horizontal;
}
.progressbar {
-moz-appearance: progressbar;
}

Summary

The Mozilla-specific values for the appearance property let you customize UI elements in Mozilla Firefox. By using these values, you can make your web designs look like native elements. However, always test your code to make sure it works well across different browsers and versions.

Resources

To learn more about the appearance property, check out these helpful resources:

  1. MDN Web Docs
    • Comprehensive documentation on the appearance property.
  2. CSS-Tricks
    • A detailed guide and tutorials on using the appearance property.
  3. Can I Use
    • Check browser compatibility for the appearance property.
  4. W3C CSS UI Module Level 4
    • Official specification for the appearance property.

Additional Resources

  1. Trent Walton on WebKit Appearance
    • Tips for using -webkit-appearance.
  2. Shaun Inman on Disabling Inner Text Shadow
    • Customizing text inputs on the iPad.
  3. CSS3 Spec
    • Detailed information on the appearance property.

Summary

These resources will help you understand and use the appearance CSS property effectively. Staying informed will help you create better web designs that work well across different devices and browsers.

Get 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.