• google plus

How to Use the CSS Clear Property

The CSS clear is used to indicate whether an element is next to elements before it or whether the element should be below the other element.

Possible values of the clear property are:

  • left
  • right
  • both
  • none

In the following example, a paragraph without a clear property applied will float to the right of the div element. The 2nd paragraph uses clear to prevent floating.
clearing floats example

The code used to create the results above is shown below:

<html>
	<head>
		<title>Demonstrating clear</title>
		<style>
			#box1 {
				float:left;
				width:100px;
				height:100px;
				background-color:red;
			}
			p.clear {
				clear:both;
			}
		</style>
	</head>
	<body>
	<div id="box1"></div>
	<p>This text floats.</p>
	<p class="clear">This text doesn't float.</p>
	</body>
</html>
Author: Chris Minnick
Chris is a prolific author and trainer, and the CEO of WatzThis?. His published books include Writing Computer Code, JavaScript for Kids, Coding with JavaScript For Dummies, Beginning HTML5 and CSS3 For Dummies, Webkit For Dummies, CIW eCommerce Certification Bible, and New Riders' XHTML.
About Webucator

Webucator provides instructor-led training to students throughout the US and Canada. We have trained over 90,000 students from over 16,000 organizations on technologies such as Microsoft ASP.NET, Microsoft Office, XML, Windows, Java, Adobe, HTML5, JavaScript, Angular, and much more. Check out our complete course catalog.