Style cssFloat Attribute

Definition and Usage

cssFloat Sets or returns the horizontal alignment of the element.

Tip:The CSS "float" property is called "cssFloat" in JavaScript because "float" is a reserved word in JavaScript.

Note:If there is not enough space for the floating element in a line, it will jump to the next line with enough space.

See Also:

CSS Tutorial:CSS Floating

Example

Example 1

When clicking on the two buttons, let the image float to the left/right of the text:

function floatRight() {
  document.getElementById("myImg").style.cssFloat = "right";
}
function floatLeft() {
  document.getElementById("myImg").style.cssFloat = "left";
}

Try It Yourself

Example 2

Change the cssFloat attribute of the DIV element:

document.getElementById("myDIV").style.cssFloat = "left";

Try It Yourself

Syntax

Return cssFloat Attribute:

object.style.cssFloat

Set cssFloat Attribute:

object.style.cssFloat = "left|right|none|initial|inherit"

Attribute Value

Value Description
none The object/element does not float. Default.
left The object/element will float to the left in the parent element.
right The object/element will float to the right in the parent element.
initial Set this attribute to its default value. See initial
inherit This attribute is inherited from its parent element. See inherit

Technical Details

Default Value: None
Return Value: String, naglalayong ang horizontal alignment ng elemento.
DOM Version: DOM Level 2

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support