WebKit-Specific Style: -webkit-appearance

By  on  

I was recently scoping out the horrid source code of the Google homepage when I noticed the "Google Search" and "I'm Feeling Lucky" buttons had a style definition I hadn't seen before:  -webkit-appearance.  The value assigned to the style was "push-button."  They are buttons so that makes sense but I was curious as to the possible values available for that style.  What I found was that there are a *ton* and that you can set any HTML element to look like a completely different element.

Possible -webkit-appearance Values

  • checkbox
  • radio
  • push-button
  • square-button
  • button
  • button-bevel
  • listbox
  • listitem
  • menulist
  • menulist-button
  • menulist-text
  • menulist-textfield
  • scrollbarbutton-up
  • scrollbarbutton-down
  • scrollbarbutton-left
  • scrollbarbutton-right
  • scrollbartrack-horizontal
  • scrollbartrack-vertical
  • scrollbarthumb-horizontal
  • scrollbarthumb-vertical
  • scrollbargripper-horizontal
  • scrollbargripper-vertical
  • slider-horizontal
  • slider-vertical
  • sliderthumb-horizontal
  • sliderthumb-vertical
  • caret
  • searchfield
  • searchfield-decoration
  • searchfield-results-decoration
  • searchfield-results-button
  • searchfield-cancel-button
  • textfield
  • textarea

The HTML

<span class="webkit-me">My Span Tag</span>

Just a SPAN tag, right?  We'll see about that.

The CSS

.webkit-me { -webkit-appearance:push-button; }

Now my span looks like a button.  Weird, huh?  It can get worse:

.webkit-me { -webkit-appearance:checkbox; }

That's right...my SPAN tag now looks like checkbox.  Weird.

Be sure to check out my demo -- I've got each -webkit-appearance setting represented.  Some elements show no change but some look downright odd!

Recent Features

  • By
    Creating Scrolling Parallax Effects with CSS

    Introduction For quite a long time now websites with the so called "parallax" effect have been really popular. In case you have not heard of this effect, it basically includes different layers of images that are moving in different directions or with different speed. This leads to a...

  • By
    6 Things You Didn&#8217;t Know About Firefox OS

    Firefox OS is all over the tech news and for good reason:  Mozilla's finally given web developers the platform that they need to create apps the way they've been creating them for years -- with CSS, HTML, and JavaScript.  Firefox OS has been rapidly improving...

Incredible Demos

  • By
    Introducing MooTools HeatMap

    It's often interesting to think about where on a given element, whether it be the page, an image, or a static DIV, your users are clicking.  With that curiosity in mind, I've created HeatMap: a MooTools class that allows you to detect, load, save, and...

  • By
    Image Manipulation with PHP and the GD Library

    Yeah, I'm a Photoshop wizard. I rock the selection tool. I crop like a farmer. I dominate the bucket tool. Hell, I even went as far as wielding the wizard wand selection tool once. ...OK I'm rubbish when it comes to Photoshop.

Discussion

  1. David

    i believe that some value not apply to span, example, menulist apply to select tag

  2. @David: Of course not, but it’s funny that it can be done. ;)

  3. Christopher Smoak

    Where do you see a need for this? Why would someone want to display an element as a checkbox or selectbox or whatever?

  4. I have seen -webkit-appearance: caret; used to remove the drop-shadows inside input types of text, email search etc on the iPad.

    Other than that it seems a fairly un-useful set of rules. Amusing that they work on the span though, maybe it’d be useful for JavaScript functionality somehow?

  5. In Opera10, Firefox 3.6.6 and IE8 dont work, in Chrome5 yes but menulist dont show the arrow, it is only ok in Safari, so , I think it’s no very useful (but yes, few funny)

  6. @penelope glamour: its a webkit style tag it gone only support webkit browser, currently only safari and chrome are webkit browser , for firefox there is -moz-appearance and for opera ie there is appearance style tag and i hope they all have same amount of option available

  7. Tymon Sturgeon

    @David Walsh: Just a quick hint: This is can be used for custom checkboxes in -webkit… :D

  8. Yeah, this thing acts as the gatekeeper for input styles — especially on the iPhone. I couldn’t get a box-shadow to apply to an input type=text, so I just set the -webkit-appearance to default-button, and boom, it worked. Same with checkboxes and radio buttons, couldn’t get custom styles like border-radius and background-gradients going, but set the type to default-button and the sky is the limit.

    There’s also a -moz-appearance, but it doesn’t work nearly as well.

    An important thing to keep in mind is that the :checked look for checkboxes and radios is also controlled by -webkit-appearance. When you set them to default-button, if you don’t set them back to their respective defaults (or apply your own :checked psuedo-class styles), they won’t show up as being checked.

  9. @David Walsh: How can i get webkit working in firefox and ie?

  10. Danz

    @RussellUresti: Curious, i cannot seem to get -moz-appearance to in any shape or form, it seems to retain whatever the element is… or is this only as -webkit-appearance can be used on spans and divs, can only be used other than form elements???

  11. K

    Work on mobile for iphone/ipad … you’ll find uses a-plenty for -webkit-appearance

  12. Victor

    When applying -webkit-appearance: button to an <a>, style of its button-like border cannot be overridden with CSS anymore. With CSS

    .button {
      -webkit-appearance: button;
      border: solid 1px #bbb;
      background-color: #888;
      color: #000;
    }
    

    button.button and a.button will look different: http://jsfiddle.net/ys4CX/1/ .

  13. According to Moz://a themself:

    The -moz-appearance CSS property is used in Gecko (Firefox) to display an element using platform-native styling based on the operating system’s theme.

    So the concept is to ‘adjust’ to the device’s OS you are using. Not very practical at all and I was looking for a Reddit thread to spurge my disdain of how awful this “experimental technology”—as Moz says—really is. Every website that uses themes or assets to _support_, and thus promoting, the rule needs this here snippet

    input {-moz-appearance: initial; border: inherit; }

    so the page doesnt show thos obnoxious quadruple checkboxes and other disastrous inputs.

    I am going with thums down on this ideology, at least for now. Moz://a is usually pretty good with creating new but this one I am not too sure about.

    • My apologies for being knee-jerk on the above comment. The article from David, above, is obviously for Webkit -appearence style. Oh well, not enough coffee for me yet.

      Hopefully it will draw some interest as a cross technology comment, if nothing else.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!