SlideShare a Scribd company logo
The HTML <select> tag
On styling it and the challenge it presents
The W3C Specification says:

• The <select> element represents a
  control for selecting amongst a set of
  options.
                                                         HTML Code
• Children tags are the options
  represented by the tag <option>


• Attributes: autofocus, disabled, form,
  multiple, name, required, size


• Source: http://www.w3.org/wiki/HTML/
  Elements/select

   - (examples are shown using a Mac Operating System)
Firefox 10 Mac OS                 IE7 Windows XP




Chrome 17 Mac OS                  Firefox 10 Windows XP




                                  Chrome 17 Windows XP


 Raw Style
 This is how the <select> looks
                                  IE8 Windows 7
 like on different browsers and
 Operating Systems with no CSS
 styles applied.

                                  Firefox 10 Windows 7
  Chrome 17 Windows 7
Firefox 10 Mac OS       IE7 Windows XP                       Chrome 17 Windows XP




                                         Firefox 10 Windows XP              Fifefox 10 Windows 7


CSS Styling
Basic styling over the <select>
tag.

Things get messy and
                                         IE8 Windows 7                     Chrome 17 Windows 7
unpredictable

CSS:
Firefox 10 Mac OS   IE7 Windows XP          Chrome 17 Windows XP        Firefox 10 Windows XP




More CSS Styling                     IE8 Windows 7                 Firefox 10 Windows 7




Advanced styling over the
<style> and <option> tags



                                     Chrome 17 Windows 7
Firefox 10 Mac OS




Limitations                        IE7 Windows XP




The <select> arrow can’t be
styled and varies from browser-
to-browser and OS.


                                  Firefox 10 Windows 7
Firefox 10 Mac OS




                                  IE7 Windows XP


Limitations
Unfortunately, the mouse
hovered <option> color can’t be
styled. It is set by the OS.
                                  Chrome 17 Windows 7
Styled <span>

Alternatives                                         sitting on top of
                                                       <select> tag


De-facing

With JavaScript we can hide the
<select> tag and place a <span>
tag on top of it which can be freely
styled.                                                                         Default
                                                                                 HTML
                                                                              scrollbar for
The <option> tags conserve the                                                 <option>
default HTML behavior.                                                            tags




                                       <option> tags conserve HTML behavior
Firefox 10 Mac OS




Alternatives
Replace <option> tags.

With JavaScript we can replace
each <option> tag for another
                                                IE 7 Windows XP
HTML tag that allows proper
styling.

Source:
http://jquery-ui.googlecode.com/svn/branches/
labs/selectmenu/index.html
De-facing




                            <option>
                         replacement to
                                                                            Custom
A very styled            control hovered
                           style color
                                                                           scroll-bar
                                                                         replacement
<select> menu
De-facing

<option> replacement

Scroll-bar replacement



                                           Semi-transparent background
The price of the alternatives (technical & long)

• All the JavaScript alternatives put work-load on the browser.

• JavaScript works with the code delivered from BackEnd: <select> and <option> tags.

  De-facing:                                       <option> replacement:

• Each <select> tag is hidden.                   • Each <select> tag is replaced with
                                                   1 <a> tag and 2 <span> tags.
• A <span> tag is introduced.
                                                 • 5 JS events are attached to the
• Both get wrapped in a <div>                      <a> tag.
  element.
                                                 • Each <option> tag is replaced
  Scroll-bar replacement:                          with a <li> & <a> tag and wrapped
                                                   in a <ul> tag.
• 4 <div> elements created to mock
  a styled scroll-bar.                           • 6 JS events are attached to each
                                                   <li> tag to emulate the HTML
• 4 JS events are attached to each                 behavior of the <select> &
  <select> menu.                                   <option> tags.
A test case - www.moneygram.com
• There are 5 <select> tags and 569 <option> tags on page-load.

• Some <select> tags get populated by AJAX calls after page-load, increasing the number of
  <option> tags.


  Costs for the browser:

• 594 HTML tag replacements.

• 3.459 JavaScript event attachments.

• Each time an AJAX call is made, new <option> tags come - HTML tag
  replacements and event attachments must be made on-the-spot.

• Our tests show that this process alone consumes 23% of the browsers available
  memory against 2% for the un-styled HTML approach.

• This is 11.5 times as intensive. Too much!
Analysis

• The a site like www.moneygram.com has too many <option> tags (500+)
  because most of them are part of a country selection list with 180+ countries.


• We don’t recommend using the <option> JavaScript replacement option as it
  consumes almost 1/4 of the browser’s memory.


• Users are already familiar with the default HTML behavior for <select> menus
  on different browsers and Operating Systems.


• The de-facing alternative offers a good styling option for the un-dropped
  <select> menu and it’s not so intensive for the browser.

More Related Content

PPT
Introduction html
PDF
Melody Designer Training
PDF
Front-End Methodologies
PPT
Html & Css presentation
KEY
Html5 use cases
PDF
JavaScript Execution Context
PDF
Web Fonts
PDF
Design in Tech Report 2017
Introduction html
Melody Designer Training
Front-End Methodologies
Html & Css presentation
Html5 use cases
JavaScript Execution Context
Web Fonts
Design in Tech Report 2017

Similar to The HTML select tag styling challenge (20)

PDF
Developing web applications in 2010
PPSX
Introduction to Html5
PDF
Html5, css3 y js
ODP
Introduction of Html/css/js
PDF
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
ODP
Html5
PDF
HTML5 and friends - Institutional Web Management Workshop 2010
PPTX
WebDesigning.pptx
PPTX
Html5 and css3
PDF
Modern Browser Support
KEY
Ease into HTML5 and CSS3
PDF
HTML5 Who what where when why how
PDF
What you need to know bout html5
PDF
Chris Wilson @ FOWA Feb 07
PPTX
Windows 8 Pure Imagination - 2012-11-24 - Getting your HTML5 game Windows 8 r...
DOC
Class 2 handout css exercises (2)
PDF
Winter%200405%20-%20Advanced%20Javascript
PDF
Winter%200405%20-%20Advanced%20Javascript
PPTX
Lessons Learned: Migrating Tests to Selenium v2
PPTX
Entering User Data from a Web Page HTML Forms
Developing web applications in 2010
Introduction to Html5
Html5, css3 y js
Introduction of Html/css/js
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Html5
HTML5 and friends - Institutional Web Management Workshop 2010
WebDesigning.pptx
Html5 and css3
Modern Browser Support
Ease into HTML5 and CSS3
HTML5 Who what where when why how
What you need to know bout html5
Chris Wilson @ FOWA Feb 07
Windows 8 Pure Imagination - 2012-11-24 - Getting your HTML5 game Windows 8 r...
Class 2 handout css exercises (2)
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascript
Lessons Learned: Migrating Tests to Selenium v2
Entering User Data from a Web Page HTML Forms
Ad

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation theory and applications.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Electronic commerce courselecture one. Pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
MYSQL Presentation for SQL database connectivity
PPT
Teaching material agriculture food technology
Building Integrated photovoltaic BIPV_UPV.pdf
Assigned Numbers - 2025 - Bluetooth® Document
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
NewMind AI Weekly Chronicles - August'25-Week II
The Rise and Fall of 3GPP – Time for a Sabbatical?
20250228 LYD VKU AI Blended-Learning.pptx
Empathic Computing: Creating Shared Understanding
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation theory and applications.pdf
Spectral efficient network and resource selection model in 5G networks
Electronic commerce courselecture one. Pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
cuic standard and advanced reporting.pdf
Unlocking AI with Model Context Protocol (MCP)
sap open course for s4hana steps from ECC to s4
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
MYSQL Presentation for SQL database connectivity
Teaching material agriculture food technology
Ad

The HTML select tag styling challenge

  • 1. The HTML <select> tag On styling it and the challenge it presents
  • 2. The W3C Specification says: • The <select> element represents a control for selecting amongst a set of options. HTML Code • Children tags are the options represented by the tag <option> • Attributes: autofocus, disabled, form, multiple, name, required, size • Source: http://www.w3.org/wiki/HTML/ Elements/select - (examples are shown using a Mac Operating System)
  • 3. Firefox 10 Mac OS IE7 Windows XP Chrome 17 Mac OS Firefox 10 Windows XP Chrome 17 Windows XP Raw Style This is how the <select> looks IE8 Windows 7 like on different browsers and Operating Systems with no CSS styles applied. Firefox 10 Windows 7 Chrome 17 Windows 7
  • 4. Firefox 10 Mac OS IE7 Windows XP Chrome 17 Windows XP Firefox 10 Windows XP Fifefox 10 Windows 7 CSS Styling Basic styling over the <select> tag. Things get messy and IE8 Windows 7 Chrome 17 Windows 7 unpredictable CSS:
  • 5. Firefox 10 Mac OS IE7 Windows XP Chrome 17 Windows XP Firefox 10 Windows XP More CSS Styling IE8 Windows 7 Firefox 10 Windows 7 Advanced styling over the <style> and <option> tags Chrome 17 Windows 7
  • 6. Firefox 10 Mac OS Limitations IE7 Windows XP The <select> arrow can’t be styled and varies from browser- to-browser and OS. Firefox 10 Windows 7
  • 7. Firefox 10 Mac OS IE7 Windows XP Limitations Unfortunately, the mouse hovered <option> color can’t be styled. It is set by the OS. Chrome 17 Windows 7
  • 8. Styled <span> Alternatives sitting on top of <select> tag De-facing With JavaScript we can hide the <select> tag and place a <span> tag on top of it which can be freely styled. Default HTML scrollbar for The <option> tags conserve the <option> default HTML behavior. tags <option> tags conserve HTML behavior
  • 9. Firefox 10 Mac OS Alternatives Replace <option> tags. With JavaScript we can replace each <option> tag for another IE 7 Windows XP HTML tag that allows proper styling. Source: http://jquery-ui.googlecode.com/svn/branches/ labs/selectmenu/index.html
  • 10. De-facing <option> replacement to Custom A very styled control hovered style color scroll-bar replacement <select> menu De-facing <option> replacement Scroll-bar replacement Semi-transparent background
  • 11. The price of the alternatives (technical & long) • All the JavaScript alternatives put work-load on the browser. • JavaScript works with the code delivered from BackEnd: <select> and <option> tags. De-facing: <option> replacement: • Each <select> tag is hidden. • Each <select> tag is replaced with 1 <a> tag and 2 <span> tags. • A <span> tag is introduced. • 5 JS events are attached to the • Both get wrapped in a <div> <a> tag. element. • Each <option> tag is replaced Scroll-bar replacement: with a <li> & <a> tag and wrapped in a <ul> tag. • 4 <div> elements created to mock a styled scroll-bar. • 6 JS events are attached to each <li> tag to emulate the HTML • 4 JS events are attached to each behavior of the <select> & <select> menu. <option> tags.
  • 12. A test case - www.moneygram.com • There are 5 <select> tags and 569 <option> tags on page-load. • Some <select> tags get populated by AJAX calls after page-load, increasing the number of <option> tags. Costs for the browser: • 594 HTML tag replacements. • 3.459 JavaScript event attachments. • Each time an AJAX call is made, new <option> tags come - HTML tag replacements and event attachments must be made on-the-spot. • Our tests show that this process alone consumes 23% of the browsers available memory against 2% for the un-styled HTML approach. • This is 11.5 times as intensive. Too much!
  • 13. Analysis • The a site like www.moneygram.com has too many <option> tags (500+) because most of them are part of a country selection list with 180+ countries. • We don’t recommend using the <option> JavaScript replacement option as it consumes almost 1/4 of the browser’s memory. • Users are already familiar with the default HTML behavior for <select> menus on different browsers and Operating Systems. • The de-facing alternative offers a good styling option for the un-dropped <select> menu and it’s not so intensive for the browser.

Editor's Notes