Relative Positioning with CSS

When elements are positioned relatively, they are positioned relative to where they would normally appear in the flow. Unlike absolutely positioned elements, relatively positioned elements do affect the positioning of subsequent sibling elements. Learn how to use relative positioning in the following steps.

  1. Set the position property to relative.
    h1 {
  3. Set one or more "offset" properties.

    The "offset" properties are top, right, bottom, and left. Their values can be specified in number of units (e.g., 10px) or percentage of the containing block (e.g., 20%).

    h1 {
    	top: 70px;
    	left: 50px;
  5. The following example demonstrates relative positioning:
    <meta charset="UTF-8">
    <style type="text/css">
    h1 {
    	border:2px solid #006;
    #explanation {
    #wrapper {
    	border:1px solid #006;
    <title>CSS Relative Positioning</title>
    <div id="wrapper">
    	<h1>CSS Relative Positioning</h1>
    	<h2>From the Left and the Top</h2>
    	<div id="explanation">
    		<p>The h1 element on this page has been positioned relative to where it otherwise would be.</p>
    		<p>All other content on the page (including these sentences) will show up in the same position it would have if the h1 had not been positioned at all.</p>
    This code renders the following:
    Relative Positioning
Author: Chris Minnick

Chris Minnick, the co-founder of WatzThis?, has overseen the development of hundreds of web and mobile projects for customers from small businesses to some of the world’s largest companies. A prolific writer, Chris has authored and co-authored books and articles on a wide range of Internet-related topics including HTML, CSS, mobile apps, e-commerce, e-business, Web design, XML, and application servers. His published books include Adventures in Coding, JavaScript For Kids For Dummies, Writing Computer Code, Coding with JavaScript For Dummies, Beginning HTML5 and CSS3 For Dummies, Webkit For Dummies, CIW E-Commerce Designer Certification Bible, and 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, Azure, Windows, Java, Adobe, Python, SQL, JavaScript, Angular and much more. Check out our complete course catalog.