CSS Properties to JavaScript Conversion


Usage

Internet Explorer

    document.all.div_id.style.JS_property_reference= "new_CSS_property_value";

Older Netscapes

    document.div_id.JS_property_reference = "new_CSS_property_value";

Netscape 6.0+ and Opera (and other Mozilla)

    document.getElementById(div_id).style.JS_property_reference ="new_CSS_property_value"
Note the use of parentheses instead of square brackets in newer Mozilla's "getElementById()" reference.

CSS Property JavaScript Reference
clear clear
clip clip
cursor cursor
display display
filter filter
left left
letter-spacing letterSpacing
line-height lineHeight
overflow overflow
page-break-after pageBreakAfter
page-break-before pageBreakBefore
position position
text-align textAlign
text-decoration textDecoration
text-decoration: blink textDecorationBlink
text-decoration: line-through textDecorationLineThrough
text-decoration: none textDecorationNone
text-decoration: overline textDecorationOverline
text-decoration: underline textDecorationUnderline
text-indent textIndent
text-transform textTransform
top top
vertical-align verticalAlign
visibility visibility
z-index zIndex

JavaScript Style Attributes

Listed below are the tables of CSS properties for various HTML element style attributes. I have added a column indicating the javaScript name that the browser recognizes for these properties. I have only listed those that I know work, but the trend seems to be to use the same name when one name is the style descriptor. When there are two names, use the first name in lower case and the first character of the second name in upper case. Examples:

Box Properties
NameJavaScript NameDescriptionPossible ValuesElement TypesExampleinherited
borderborder Sets border width, style and color. See border width, style, and color All{border: medium solid green} No
border-bottomborderBottom Set the bottom border width style, and color. See border width, style, and color All{border-bottom: medium solid green} No
border-bottom-widthborderBottomWidth Set the bottom border widththin, medium, thick, or length value All{border-bottom-width: thin} No
border-colorborderColor Set the border colorA color value, color, #RRGGBB All{border: #0000ff} No
border-leftborderLeft Set the left border width style, and color. See border width, style, and color All{border-left: medium solid green} No
border-left-widthborderLeftWidth Set the left border widththin, medium, thick, or length value All{border-left-width: thin} No
border-rightborderRight Set the right border width style, and color. See border width, style, and color All{border-right: medium solid green} No
border-right-widthborderRightWidth Set the right border widththin, medium, thick, or length value All{border-right-width: thin} No
border-styleborderStyle Sets border stylenone, dotted, dashed, solid, double, groove, ridge, inset, outset All{border: dashed} No
border-topborderTop Set the top border width style, and color. See border width, style, and color All{border-top: medium solid green} No
border-top-widthborderTopWidth

Set the top border widththin, medium, thick, or length value All{border-top-width: thin} No
border-widthborderWidth Sets Border width.thin, medium, thick, or length value All{border-width: 8} No
clearclear

Determines where floating elements are allowed. none, left, right, bothAll {clear: left}No
border-bottom-style

 

borderBottomStyle     
border-left-color

 

borderLeftColor     
border-left-style

 

borderLeftStyle

 

     
border-right-color

 

borderRightColor

 

     
border-right-style

 

borderRightStyle

 

     
border-top-color

 

borderTopColor     
floatstyleFloat Specifies how text is wrapped and where it is aligned. none, left, rightAll {float: left}No
heightheight Height of elementauto or a height value Block elements and IMG, INPUT, TEXTAREA, SELECT, and OBJECT {height: 200}No
marginmargin Set element margin width. A single value sets all margins, two values set top and bottom, four values set top, right, bottom, and left margins. auto, length value, or percent value All{margin: 4em 2em 4em 2em} No
margin-bottommarginBottom Set element bottom marginlength value, or percent value All{margin-bottom: 4em} No
margin-leftmarginLeft Set element left marginlength value, or percent value All{margin-left: 4em} No
margin-rightmarginRight Set element right marginlength value, or percent value All{margin-right: 4em} No
margin-topmarginTop Set element top marginlength value, or percent value All{margin-top: 4em} No
paddingpadding Space between border and content. A single value sets all sides, two values set top/bottom and left/right, three values set top, right/left, and bottom, and four values set top, right, bottom, and left. length value, or percent value All{padding: 4em} No
padding-bottompaddingBottom Space between bottom border and content. length value, or percent valueAll {padding-bottom: 4em}No
padding-leftpaddingLeft Space between left border and content. length value, or percent valueAll {padding-left: 4em}No
padding-rightpaddingRight Space between right border and content. length value, or percent valueAll {padding-right: 4em}No
padding-toppaddingTop Space between top border and content. length value, or percent valueAll {padding-top: 4em}No
widthwidth Width of elementauto or a height value in length or percentage Block elements and IMG, INPUT, TEXTAREA, SELECT, and OBJECT {width: 40em}No
Background and Color Properties
NameJavaScript NameDescriptionPossible ValuesElement TypesExampleinherited
backgroundbackground Set background color, repeat, image, attachment, or position.See background-color, background-image, background-attachment, background-repeat, background-position All{background: #8080ff}No
background-attachmentbackgroundAttachment Determines if the background image is fixed or scroll.scroll, fixedAll{background-attachment: scroll}No
background-colorbackgroundColorSets the background color.Named or value colorAll{background-color: #8080ff}No
background-image  Sets the background image.urlAll{background-image: url('../../../../gifs/flowers.gif')}No
background-positionbackgroundImage Sets the background image initial position.top, center, bottom, left, center, right, or percent valuesBlock and IMG, INPUT, TEXTAREA, SELECT, and OBJECT{background-position: left top}No
background-repeatbackgroundRepeat Sets how the background image is repeated.repeat, repeat-x, repeat-y, no-repeatAll{background-repeat: no-repeat}No
colorcolorSets element color.Named or value colorAll{color: green}Yes
Classification Properties
NameJavaScript NameDescriptionPossible ValuesElement TypesExampleinherited
display  Sets the type of element.block, inline, list-item, noneAll{display: list-item}No
list-stylelistStyleSets list style type and/or position.See list-style-type and list-style-positionList-item{list-style: circle}Yes
list-style-imagelistStyleImage Sets image to be used as the list item marker.urlList-item{list-style-image: url(this.gif)}Yes
list-style-typelistStyleType Sets list style type.circle, disc, decimal, lower-alpha, lower-roman, none, square, upper-alpha, upper-romanList-item{list-style-type: square}Yes
list-style-positionlistStylePosition Sets where the marker is place relative to the text and its wrapping position.inside, outsideList-item{list-style: circle}Yes
whitespace  Sets treatment of spaces inside the element.normal, pre, nowrapBlock{whitespace: pre}Yes
Font Properties
NameJavaScript NameDescriptionPossible ValuesElement TypesExampleinherited
fontfont  Used to define font propertiesSee font-family, font-size, font-style, font-variant, and font-weight.All{font: 20pt}Yes
font-familyfontFamilyUsed to define font family to usefamily nameAll{font-family: ariel roman}Yes
font-sizefontSize  Used to define font size to usexx-small, x-small, small, medium, large, x-large, xx-large, larger, smaller, length value, or percent valueAll{font-size: 18pt}Yes
font-stylefontStyleUsed to define font style to usenormal, italic, obliqueAll{font-style: italic}Yes
font-variantfontVariantUsed to determine whether to use normal or small capsnormal, small-capsAll{font-variant: small-caps}Yes
font-weightfontWeightSets font weight.normal, bold, bolder, lighter, 100, 200, 300, 400, 500, 600, 700, 800, 900All{font-weight: 600}Yes
Text Properties
NameJavaScript NameDescriptionPossible ValuesElement TypesExampleinherited
letter-spacingletterSpacing Sets the space between characters.normal or length valueAll{letter-spacing: 0.2em}Yes
line-heightlineHeightSets the height of lines.normal, a number, a percent of the element font size,All{line-height: 2}Yes
text-aligntextAlignSets the alignment of text.left, right, center, justifyBlock{text-align: center}Yes
text-decorationtextDecorationSets the special decoration attributes of text.none, overline, underline, line-through, blinkAll{text-decoration: blink}No
text-indenttextIndentSets the element's first line amount of indentation.length or percentage valueBlock{text-indent: 5%}Yes
text-transformtextTransformTransforms text to one of the set values.none, capitalize, uppercase, lowercaseAll{text-transform: uppercase}Yes
vertical-alignverticalAlignSets vertical position.baseline, sub. super, top, middle, bottom, text-top, text-bottom, or percent valueInline{vertical-align: sub}No
word-spacing  Sets extra space between words.normal or length valueAll{word-spacing: 0.2em}Yes