{"id":4950,"date":"2020-06-30T14:14:00","date_gmt":"2020-06-30T14:14:00","guid":{"rendered":"https:\/\/azoora.com\/blog\/?p=4950"},"modified":"2020-08-18T14:28:19","modified_gmt":"2020-08-18T14:28:19","slug":"create-simple-parallax-scrolling-effect-in-hero-section-using-pure-css","status":"publish","type":"post","link":"https:\/\/azoora.com\/blog\/code\/create-simple-parallax-scrolling-effect-in-hero-section-using-pure-css\/","title":{"rendered":"Create Simple Parallax Scrolling Effect in Hero Section using Pure CSS"},"content":{"rendered":"\n<p>In this tutorial you will learn how to create a simple pure CSS parallax scrolling effect in the hero section of your landing page. Parallax scrolling is an effect where different visual elements on the page move at different speeds when the user scrolls. This creates a 3D effect adding a sense of depth and enhancing the visitor\u2019s experience. This GIF shows what you will be able to create by the end of this tutorial.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-attachment-id=\"4951\" data-permalink=\"https:\/\/azoora.com\/blog\/code\/create-simple-parallax-scrolling-effect-in-hero-section-using-pure-css\/attachment\/example-pure-css-parallax\/#main\" data-orig-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/example-pure-css-parallax.gif\" data-orig-size=\"450,284\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"example-pure-css-parallax\" data-image-description=\"\" data-medium-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/example-pure-css-parallax-300x189.gif\" data-large-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/example-pure-css-parallax.gif\" loading=\"lazy\" width=\"450\" height=\"284\" src=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/example-pure-css-parallax.gif\" alt=\"\" class=\"wp-image-4951\"\/><\/figure>\n\n\n\n<p>You need to have basic knowledge of HTML and CSS to begin with. We will dive into a few advanced CSS topics such as&nbsp;<code>perspective<\/code>&nbsp;and&nbsp;<code>transform<\/code>&nbsp;towards the end. Let\u2019s get started.<\/p>\n\n\n\n<p>We are going to break this tutorial into two parts. In the first part we will be achieving almost the same look and feel of the page except for the parallax effect. That is, there will be no 3D effect. Just simple scrolling. If you already know how to do this, you can quickly rush through\u00a0<strong>Part 01<\/strong>. In the second part, we will learn the advanced CSS concepts required and create the parallax scrolling effect.<\/p>\n\n\n\n<h2>Part 01: Without parallax<\/h2>\n\n\n\n<p>Looking at the GIF, you can see that we have a header section with a background image occupying full viewport width and height, followed by a text section. Let us create this step by step.<\/p>\n\n\n\n<h4>Setting up<\/h4>\n\n\n\n<p>Create a blank HTML document and name it&nbsp;<code>index.html<\/code>. Add the basic HTML skeleton. If you use Visual Studio Code, all you need to do is type \u201c!\u201d and hit enter. You will end up with this.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td><code>&lt;!<\/code><code>DOCTYPE<\/code> <code>html&gt;<\/code><code>&lt;<\/code><code>html<\/code> <code>lang<\/code><code>=<\/code><code>\"en\"<\/code><code>&gt;<\/code><code>&lt;<\/code><code>head<\/code><code>&gt;<\/code><code>&lt;<\/code><code>meta<\/code> <code>charset<\/code><code>=<\/code><code>\"UTF-8\"<\/code><code>&gt;<\/code><code>&lt;<\/code><code>meta<\/code> <code>name<\/code><code>=<\/code><code>\"viewport\"<\/code> <code>content<\/code><code>=<\/code><code>\"width=device-width, initial-scale=1.0\"<\/code><code>&gt;<\/code><code>&lt;<\/code><code>title<\/code><code>&gt;Document&lt;\/<\/code><code>title<\/code><code>&gt;<\/code><code>&lt;\/<\/code><code>head<\/code><code>&gt;<\/code><code>&lt;<\/code><code>body<\/code><code>&gt; <\/code>&nbsp;<code>&lt;\/<\/code><code>body<\/code><code>&gt;<\/code><code>&lt;\/<\/code><code>html<\/code><code>&gt;<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>I have used the font \u2018Roboto\u2019 for the heading and \u2018Lato\u2019 for the paragraphs. So add the following line below the title tag to embed these using Google fonts.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td><code>&lt;<\/code><code>link<\/code> <code>href<\/code><code>=<\/code><code>\"<a href=\"https:\/\/fonts.googleapis.com\/css2?family=Lato:wght@300&amp;family=Roboto\">https:\/\/fonts.googleapis.com\/css2?family=Lato:wght@300&amp;family=Roboto<\/a>+Condensed:wght@300;700&amp;display=swap\"<\/code> <code>rel<\/code><code>=<\/code><code>\"stylesheet\"<\/code><code>&gt;<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Create your stylesheet and name it&nbsp;<code>style.css<\/code>. Link the stylesheet to your HTML document below the Font Awesome CDN link using<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td><code>&lt;<\/code><code>link<\/code> <code>rel<\/code><code>=<\/code><code>\"stylesheet\"<\/code> <code>href<\/code><code>=<\/code><code>\"style.css\"<\/code><code>&gt;<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>You can download the background image used in the demo from&nbsp;<a href=\"https:\/\/www.pexels.com\/photo\/blank-business-composition-computer-373076\/\" target=\"_blank\" rel=\"noreferrer noopener\">Pexels<\/a>&nbsp;or choose to include your own. But don\u2019t forget to name it&nbsp;<code>bg.jpg<\/code>.<\/p>\n\n\n\n<h4>HTML<\/h4>\n\n\n\n<p>Add the following HTML code within&nbsp;<code>body<\/code>&nbsp;for the header:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td><code>&lt;<\/code><code>header<\/code><code>&gt;<\/code><code>&lt;<\/code><code>div<\/code><code>&gt;<\/code><code>&lt;<\/code><code>h1<\/code><code>&gt;Parallax Scrolling Effect&lt;\/<\/code><code>h1<\/code><code>&gt;<\/code><code>&lt;<\/code><code>h2<\/code><code>&gt;Create this simple parallax effect using pure CSS&lt;\/<\/code><code>h2<\/code><code>&gt;<\/code><code>&lt;\/<\/code><code>div<\/code><code>&gt;<\/code><code>&lt;\/<\/code><code>header<\/code><code>&gt;<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Add the text section below that.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td><code>&lt;<\/code><code>section<\/code><code>&gt;<\/code><code>&lt;<\/code><code>div<\/code> <code>class<\/code><code>=<\/code><code>\"container\"<\/code><code>&gt;<\/code><code>&lt;<\/code><code>h3<\/code><code>&gt;Some cool title here&lt;\/<\/code><code>h3<\/code><code>&gt;<\/code><code>&lt;<\/code><code>p<\/code><code>&gt;<\/code><code>Lorem ipsum dolor sit amet consectetur adipisicing elit. Asperiores harum veritatis nemo magni odio reprehenderit atque, esse animi porro suscipit vero nobis modi quis. Exercitationem quasi beatae, assumenda officia illum sunt. Cum voluptas maiores vitae eius hic inventore deleniti placeat perferendis quam ut nostrum maxime optio voluptatibus ab laboriosam, quia consectetur atque minus?<\/code><code>&lt;\/<\/code><code>p<\/code><code>&gt;<\/code><code>&lt;<\/code><code>p<\/code><code>&gt;<\/code><code>Adipisci amet aut sint voluptates delectus aperiam? Veniam ab illum enim in libero nihil culpa explicabo perspiciatis veritatis non repellendus architecto excepturi nostrum porro voluptatem aperiam animi asperiores, a voluptatibus temporibus minima voluptas ipsa! Recusandae nostrum, aut, voluptates est error iusto, eaque excepturi soluta quas maiores amet.<\/code>&nbsp;<code>&lt;\/<\/code><code>p<\/code><code>&gt;<\/code><code>&lt;\/<\/code><code>div<\/code><code>&gt;<\/code><code>&lt;\/<\/code><code>section<\/code><code>&gt;<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Everything else is now taken care of by CSS.<\/p>\n\n\n\n<h4>CSS<\/h4>\n\n\n\n<p>In&nbsp;<code>style.css<\/code>, begin with some common styles for all elements:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td><code>* {<\/code><code>margin<\/code><code>: <\/code><code>0<\/code><code>;<\/code><code>padding<\/code><code>: <\/code><code>0<\/code><code>;<\/code><code>box-sizing<\/code><code>: <\/code><code>border-box<\/code><code>;<\/code><code>}<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Add these styles to&nbsp;<code>html<\/code>&nbsp;and&nbsp;<code>body<\/code>:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td><code>html {<\/code><code>width<\/code><code>: <\/code><code>100%<\/code><code>;<\/code><code>height<\/code><code>: <\/code><code>100%<\/code><code>;<\/code><code>}<\/code><code>body {<\/code><code>width<\/code><code>: <\/code><code>100%<\/code><code>;<\/code><code>height<\/code><code>: <\/code><code>100%<\/code><code>;<\/code><code>\/* Text styles *\/<\/code><code>font-family<\/code><code>: <\/code><code>'Lato'<\/code><code>,<\/code><code>sans-serif<\/code><code>;<\/code><code>font-size<\/code><code>: <\/code><code>18px<\/code><code>;<\/code><code>font-weight<\/code><code>: <\/code><code>300<\/code><code>;<\/code><code>color<\/code><code>: <\/code><code>#212121<\/code><code>;<\/code><code>}<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Make the&nbsp;<code>header<\/code>&nbsp;occupy full viewport width and height.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td><code>header {<\/code><code>width<\/code><code>: <\/code><code>100%<\/code><code>;<\/code><code>min-height<\/code><code>: <\/code><code>100<\/code><code>vh;<\/code><code>position<\/code><code>: <\/code><code>relative<\/code><code>;<\/code><code>}<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Let\u2019s create the&nbsp;<code>::before<\/code>&nbsp;pseudo element for header and add the background image.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td><code>header::before {<\/code><code>content<\/code><code>: <\/code><code>\"\"<\/code><code>;<\/code><code>position<\/code><code>: <\/code><code>absolute<\/code><code>;<\/code><code>top<\/code><code>: <\/code><code>0<\/code><code>;<\/code><code>left<\/code><code>: <\/code><code>0<\/code><code>;<\/code><code>right<\/code><code>: <\/code><code>0<\/code><code>;<\/code><code>bottom<\/code><code>: <\/code><code>0<\/code><code>;<\/code><code>display<\/code><code>: <\/code><code>block<\/code><code>;<\/code><code>background<\/code><code>: <\/code><code>url<\/code><code>(<\/code><code>'bg.jpg'<\/code><code>);<\/code><code>background-size<\/code><code>: <\/code><code>cover<\/code><code>;<\/code><code>z-index<\/code><code>: <\/code><code>0<\/code><code>;<\/code><code>}<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>You can now see your image occupying full screen. Now let\u2019s bring the text in front and give it the required styling:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td><code>header div {<\/code><code>position<\/code><code>: <\/code><code>absolute<\/code><code>;<\/code><code>z-index<\/code><code>: <\/code><code>1<\/code><code>;<\/code><code>top<\/code><code>: <\/code><code>50%<\/code><code>;<\/code><code>padding<\/code><code>: <\/code><code>0<\/code> <code>30px<\/code><code>;<\/code><code>font-family<\/code><code>: <\/code><code>'Roboto Condensed'<\/code><code>, <\/code><code>sans-serif<\/code><code>;<\/code><code>}<\/code><code>header h<\/code><code>1<\/code> <code>{<\/code><code>font-size<\/code><code>: <\/code><code>4.5<\/code><code>rem;<\/code><code>font-weight<\/code><code>: <\/code><code>700<\/code><code>;<\/code><code>color<\/code><code>: <\/code><code>#009688<\/code><code>;<\/code><code>}<\/code><code>header h<\/code><code>2<\/code> <code>{<\/code><code>font-size<\/code><code>: <\/code><code>2.2<\/code><code>rem;<\/code><code>font-weight<\/code><code>: <\/code><code>300<\/code><code>;<\/code><code>}<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>You can now see this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-attachment-id=\"4952\" data-permalink=\"https:\/\/azoora.com\/blog\/code\/create-simple-parallax-scrolling-effect-in-hero-section-using-pure-css\/attachment\/pure-css-parallax-01\/#main\" data-orig-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/pure-css-parallax-01.png\" data-orig-size=\"1024,640\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"pure-css-parallax-01\" data-image-description=\"\" data-medium-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/pure-css-parallax-01-300x188.png\" data-large-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/pure-css-parallax-01-1024x640.png\" loading=\"lazy\" width=\"1024\" height=\"640\" src=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/pure-css-parallax-01-1024x640.png\" alt=\"\" class=\"wp-image-4952\" srcset=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/pure-css-parallax-01.png 1024w, https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/pure-css-parallax-01-300x188.png 300w, https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/pure-css-parallax-01-768x480.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Add these to style the text section:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td><code>section{<\/code><code>width<\/code><code>: <\/code><code>100%<\/code><code>;<\/code><code>background<\/code><code>: <\/code><code>white<\/code><code>;<\/code><code>}<\/code><code>.container {<\/code><code>margin<\/code><code>: <\/code><code>auto<\/code><code>; <\/code><code>\/* To center the text horizontally *\/<\/code><code>max-width<\/code><code>: <\/code><code>1000px<\/code><code>; <\/code><code>\/* Limiting the width for extra large screens *\/<\/code><code>padding<\/code><code>: <\/code><code>80px<\/code> <code>40px<\/code><code>;<\/code><code>}<\/code><code>.container h<\/code><code>3<\/code> <code>{<\/code><code>font-family<\/code><code>: <\/code><code>'Roboto Condensed'<\/code><code>, <\/code><code>sans-serif<\/code><code>;<\/code><code>font-weight<\/code><code>: <\/code><code>700<\/code><code>;<\/code><code>font-size<\/code><code>: <\/code><code>3<\/code><code>rem;<\/code><code>}<\/code><code>.container p {<\/code><code>padding-top<\/code><code>: <\/code><code>30px<\/code><code>;<\/code><code>line-height<\/code><code>: <\/code><code>1.8<\/code><code>;<\/code><code>}<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>So far we haven\u2019t done anything exciting yet. Let\u2019s get to\u00a0<strong>Part 02<\/strong>\u00a0where we create the actual magic (with just 8 more lines of CSS).<\/p>\n\n\n\n<h2>Part 02: Adding parallax effect<\/h2>\n\n\n\n<p>To create a parallax effect we need to create a sense of depth by introducing a 3rd dimension. The CSS property&nbsp;<code>perspective<\/code>&nbsp;helps us do just that. Let\u2019s say we add&nbsp;<code>perspective:20px<\/code>&nbsp;to an element. This gives a depth of 20px to that element. This means, a 3D space is created, and so the child elements can be transformed to make them appear to be positioned near or far from the viewer, creating a sense of depth.<\/p>\n\n\n\n<p>So let\u2019s add&nbsp;<code>perspective<\/code>&nbsp;to our&nbsp;<code>body<\/code>&nbsp;element along with&nbsp;<code>overflow<\/code>&nbsp;properties.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td><code>body {<\/code><code>\/* Existing styles here *\/<\/code><code>perspective<\/code><code>: <\/code><code>4px<\/code><code>; <\/code><code>\/* The depth *\/<\/code><code>overflow-x<\/code><code>: <\/code><code>hidden<\/code><code>;<\/code><code>overflow-y<\/code><code>: <\/code><code>scroll<\/code><code>;<\/code><code>}<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The&nbsp;<code>overflow-x<\/code>&nbsp;is hidden because we do not want any horizontal scrollbar resulting due to the 3D space created.<\/p>\n\n\n\n<p>We also need to set&nbsp;<code>overflow: hidden<\/code>&nbsp;to the root element.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td><code>html {<\/code><code>\/* Existing styles here *\/<\/code><code>overflow<\/code><code>: <\/code><code>hidden<\/code><code>;<\/code><code>}<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>If you check your browser now, nothing has changed yet. It\u2019s because we have just created the 3D space but not transformed any objects within.<\/p>\n\n\n\n<p>The parallax effect happens when two or more elements are placed at different distances from the viewer. For that, we use the CSS&nbsp;<code>transform<\/code>&nbsp;property and \u201ctranslate\u201d the objects along the z-axis. So let\u2019s transform the background image and the&nbsp;<code>div<\/code>&nbsp;within the header.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td><code>header::before {<\/code><code>\/* Existing styles here *\/<\/code><code>transform<\/code><code>: translateZ(<\/code><code>-4px<\/code><code>);<\/code><code>}<\/code><code>header div {<\/code><code>\/* Existing styles here *\/<\/code><code>transform<\/code><code>: translateZ(<\/code><code>-2px<\/code><code>);<\/code><code>}<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>We are moving the background image&nbsp;<code>4px<\/code>&nbsp;away from the viewer and the headings&nbsp;<code>2px<\/code>&nbsp;away. So when you scroll down, they seem to move at different speeds. Check your browser now. Still nothing right?<\/p>\n\n\n\n<p>When we want the objects to be transformed in a 3D space, we need an additional&nbsp;<code>transform-style<\/code>&nbsp;property. This property when applied to an element, determines if that element\u2019s children are positioned in 3D space, or flattened.<\/p>\n\n\n\n<p>To understand perspective, transforms and all this in more depth, you can refer to the detailed guide to&nbsp;<a href=\"https:\/\/blog.logrocket.com\/the-noobs-guide-to-3d-transforms-with-css-7370aafd9edf\/\" target=\"_blank\" rel=\"noreferrer noopener\">3D transforms with CSS<\/a>.<\/p>\n\n\n\n<p>For now, add this property to header:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td><code>header {<\/code><code>\/* Existing styles here *\/<\/code><code>transform-style<\/code><code>: preserve<\/code><code>-3<\/code><code>d;<\/code><code>}<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Now look at the result in your browser. Surprised to see that your background image and headings have shrunk in size? Keeping that aside for a moment, scroll down and you will see that the parallax effect is actually created! Why did these two elements shrink? It\u2019s because they have moved farther away from you, remember? Objects that move farther appear smaller. Simple. But how to fix this? There\u2019s a&nbsp;<code>scale<\/code>&nbsp;factor to be added along with&nbsp;<code>translateZ<\/code>&nbsp;to correct the size. This&nbsp;<a href=\"https:\/\/developers.google.com\/web\/updates\/2016\/12\/performant-parallaxing#adjusting_scale_for_perspective\" target=\"_blank\" rel=\"noreferrer noopener\">Google article<\/a>&nbsp;gives us a formula to calculate the&nbsp;<code>scale<\/code>&nbsp;to apply.<\/p>\n\n\n\n<p><code>scale = (perspective - distance) \/ perspective<\/code><\/p>\n\n\n\n<p>For our background image,&nbsp;<code>perspective<\/code>&nbsp;is&nbsp;<code>4px<\/code>&nbsp;and distance (<code>translateZ<\/code>) is&nbsp;<code>-4px<\/code>. Calculate:<\/p>\n\n\n\n<p><code>scale = (4 - (-4))\/4 = 8\/4 = 2<\/code><\/p>\n\n\n\n<p>Similarly, for&nbsp;<code>header div<\/code>, the scale is 1.5. Let\u2019s include these. Change the&nbsp;<code>transform<\/code>&nbsp;properties of both the elements to include&nbsp;<code>scale<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td><code>header::before {<\/code><code>transform<\/code><code>: translateZ(<\/code><code>-4px<\/code><code>) <\/code><code>scale<\/code><code>(<\/code><code>2<\/code><code>);<\/code><code>}<\/code><code>header div {<\/code><code>transform<\/code><code>: translateZ(<\/code><code>-2px<\/code><code>) <\/code><code>scale<\/code><code>(<\/code><code>1.5<\/code><code>);<\/code><code>}<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>This fixes it. Now scroll down. Do you see the effect? The only issue is that our text section is being overlapped by the header. The solution to this is to set a higher&nbsp;<code>z-index<\/code>&nbsp;to the&nbsp;<code>section<\/code>&nbsp;(along with a&nbsp;<code>position<\/code>&nbsp;property, otherwise&nbsp;<code>z-index<\/code>&nbsp;won\u2019t work).<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"\"><tbody><tr><td><code>section{<\/code><code>\/* Existing styles here *\/<\/code><code>position<\/code><code>: <\/code><code>relative<\/code><code>;<\/code><code>z-index<\/code><code>: <\/code><code>2<\/code><code>;<\/code><code>}<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>And there it is! A simple neat parallax scrolling effect for our hero section is achieved.<\/p>\n\n\n\n<p>Extend this newly acquired skill and go create beautiful, pure CSS parallax scrolling websites. But be careful not to overdo it. If you got stuck somewhere in between and couldn\u2019t achieve the desired output, here\u2019s the complete source code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial you will learn how to create a simple pure CSS parallax scrolling effect in the hero section of your landing page. Parallax scrolling is an effect where different visual elements on the page move at different speeds when the user scrolls. This creates a 3D effect adding a sense of depth and [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":4952,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[4,145],"tags":[25,56,94,146,136,116,217],"jetpack_featured_media_url":"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/pure-css-parallax-01.png","jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/p7FQPL-1hQ","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/posts\/4950"}],"collection":[{"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/comments?post=4950"}],"version-history":[{"count":1,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/posts\/4950\/revisions"}],"predecessor-version":[{"id":4953,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/posts\/4950\/revisions\/4953"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/media\/4952"}],"wp:attachment":[{"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/media?parent=4950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/categories?post=4950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/tags?post=4950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}