- HTML Tutorial
- HTML - Home
- HTML - Introduction
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Headings
- HTML - Paragraphs
- HTML - Fonts
- HTML - Blocks
- HTML - Style Sheet
- HTML - Formatting
- HTML - Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - Modernizr
Modernizr is a small JavaScript Library that detects whether a particular feature of web technologies is available or not in the user’s browser. It provides an easy way to detect any new feature so that we can take corresponding action based on the browser’s capabilities. For example, if a browser does not support a video feature then we can display a simple message regarding the same. We can also create CSS rules based on the feature availability and these rules would be applied automatically on the webpage if the browser does not support a new feature.
Before we start using Modernizr, we are required to include its javascript library in our HTML page header as follows −
<script src="modernizr.min.js" type="text/javascript"></script>
Instance
Following is the simple syntax to handle supported and non supported features −
<!-- In your CSS: --> .no-audio #music { display: none; <!-- to not show Audio options --> } .audio #music button { <!-- Style the Play and Pause buttons nicely --> } <!-- In your HTML: --> <div id="music"> <audio> <source src="audio.ogg" /> <source src="audio.mp3" /> </audio> <button id="play">Play</button> <button id="pause">Pause</button> </div>
Here it is notable that you need to prefix "no-" to every feature/property you want to handle for the browser which does not support them.
Following code snippet can be added to detect a particular feature through Javascript −
if (Modernizr.audio) { <!-- properties for browsers that support audio --> } else{ <!-- properties for browsers that does not support audio --> }
Features detected by Modernizr
Following is the list of features which can be detected by Modernizr −
Feature | CSS Property | JavaScript Check |
---|---|---|
@font-face | .fontface | Modernizr.fontface |
Canvas | .canvas | Modernizr.canvas |
Canvas Text | .canvastext | Modernizr.canvastext |
HTML Audio | .audio | Modernizr.audio |
HTML Audio formats | NA | Modernizr.audio[format] |
HTML Video | .video | Modernizr.video |
HTML Video Formats | NA | Modernizr.video[format] |
rgba() | .rgba | Modernizr.rgba |
hsla() | .hsla | Modernizr.hsla |
border-image | .borderimage | Modernizr.borderimage |
border-radius | .borderradius | Modernizr.borderradius |
box-shadow | .boxshadow | Modernizr.boxshadow |
Multiple backgrounds | .multiplebgs | Modernizr.multiplebgs |
opacity | .opacity | Modernizr.opacity |
CSS Animations | .cssanimations | Modernizr.cssanimations |
CSS Columns | .csscolumns | Modernizr.csscolumns |
CSS Gradients | .cssgradients | Modernizr.cssgradients |
CSS Reflections | .cssreflections | Modernizr.cssreflections |
CSS 2D Transforms | .csstransforms | Modernizr.csstransforms |
CSS 3D Transforms | .csstransforms3d | Modernizr.csstransforms3d |
CSS Transitions | .csstransitions | Modernizr.csstransitions |
Geolocation API | .geolocation | Modernizr.geolocation |
Input Types | NA | Modernizr.inputtypes[type] |
Input Attributes | NA | Modernizr.input[attribute] |
localStorage | .localstorage | Modernizr.localstorage |
sessionStorage | .sessionstorage | Modernizr.sessionstorage |
Web Workers | .webworkers | Modernizr.webworkers |
applicationCache | .applicationcache | Modernizr.applicationcache |
SVG | .svg | Modernizr.svg |
SVG Clip Paths | .svgclippaths | Modernizr.svgclippaths |
SMIL | .smil | Modernizr.smil |
Web SQL Database | .websqldatabase | Modernizr.websqldatabase |
IndexedDB | .indexeddb | Modernizr.indexeddb |
Web Sockets | .websockets | Modernizr.websockets |
Hashchange Event | .hashchange | Modernizr.hashchange |
History Management | .historymanagement | Modernizr.historymanagement |
Drag and Drop | .draganddrop | Modernizr.draganddrop |
Cross-window Messaging | .crosswindowmessaging | Modernizr.crosswindowmessaging |
addTest() Plugin API | NA | Modernizr.addTest(str,fn) |