width

Description

width defines the width of an element's content area.

ItemValue
Initial value auto
Inherited No.
Version CSS1
JavaScript syntax object.style.width="50px"
Applies to Block-level and replaced elements.

Syntax and Property Values


width: length  | percentage  | auto | inherit

The property values are listed in the following table.

ValueDescription
auto Default value. The browser does the calculation.
length Set width in px, cm, etc.
% Set width in percent of the containing element
inherit Inherit the width property from the parent element

Example


<!DOCTYPE HTML>
<html>
     <head>
         <style>
          p {<!--  w  w  w.ja  v a 2 s .co  m-->
              margin: 10px;
              padding: 10px;
              color: black;
              border: thin solid;
              width: 250px;
              top: 100px;
              line-height: 3em;
              font-size: 1em;
          }
         </style>
     </head>
     <body>
        <p>
          this is a test. java2s.com 
          this is a test. this is a test. this is a test. this is a test. 
          this is a test. this is a test. this is a test. this is a test. 
        </p>
     </body>
 </html>
 

Click to view the demo

The code above generates the following result.

width




















Home »
  HTML CSS »
    HTML CSS Reference »




HTML Tag Reference
CSS Reference
CSS Selector Reference
Encoding Reference