HTML CSS Bootstrap Javascript Icons Python
HTML References
HTML - Tag Reference HTML - Tag by Category HTML - Attributes HTML - Global Attributes HTML - Events HTML - Language Codes HTML - Country Codes HTML - URL Encoding HTTP Methods HTTP Status Codes <input> types
All HTML Tags
<!-- --> <!DOCTYPE> <a> <abbr> <acronym> <address> <applet> <area> <article> <aside> <audio> <b> <base> <basefont> <bdi> <bdo> <big> <blockquote> <body> <br> <button> <canvas> <caption> <center> <cite> <code> <col> <colgroup> <data> <datalist> <dd> <del> <details> <dfn> <dialog> <dir> <div> <dl> <dt> <em> <embed> <fieldset> <figcaption> <figure> <font> <footer> <form> <frame> <frameset> <h1> - <h6> <head> <header> <hr> <html> <i> <iframe> <img> <input> <ins> <kbd> <label> <legend> <li> <link> <main> <map> <mark> <meta> <meter> <nav> <noframes> <noscript> <object> <ol> <optgroup> <option> <output> <p> <param> <picture> <pre> <progress> <q> <rp> <rt> <ruby> <s> <samp> <script> <section> <select> <small> <source> <span> <strike> <strong> <style> <sub> <summary> <sup> <svg> <table> <tbody> <td> <template> <textarea> <tfoot> <th> <thead> <time> <title> <tr> <track> <tt> <u> <ul> <var> <video> <wbr>

HTML <div> tag

The HTML <div> element is the generic container for flow content. It has no effect on the content or layout until styled using CSS.

Run code

As a "pure" container, the <div> element does not inherently represent anything. Instead, it's used to group content so it can be easily styled using the class or id attributes (See Examples below).

The difference between the div tag and the span tag is that the div tag is used with blocklevel elements whilst the span tag is used with inline elements.

Browser compatibility

The <div> element is fully supported by all browsers:

Element
<div> yes yes yes yes yes



Attributes

The following table shows the attributes that are specific to the <div> tag:

Attribute Value Description
align left
right
center
justify
Not supported in HTML5. Use CSS text-align property instead.
Specifies the alignment of the content inside a div element

Global Attributes

The <div> tag supports the global attributes described in HTML Global Attributes Reference

Event Attributes

The <div> tag supports the event attributes described in HTML Events Reference


More Examples

This example creates a colored box by applying a style to the <div> using CSS. Note the use of the id attribute on the <div> to apply the style named "info" to the element:

Run code

You can define style rules based on the class attribute of the elements. All the elements having that class will be formatted according to the defined rule:

Run code

Last updated: Friday 21 Sep, 2018