Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • CSS Tutorial
  • CSS Exercises
  • CSS Interview Questions
  • CSS Selectors
  • CSS Properties
  • CSS Functions
  • CSS Examples
  • CSS Cheat Sheet
  • CSS Templates
  • CSS Frameworks
  • Bootstrap
  • Tailwind
  • CSS Formatter
Open In App
Next Article:
How to create Vertical Menu using HTML and CSS ?
Next article icon

How to Set Vertical Space Between the List of Items using CSS?

Last Updated : 15 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Vertical space refers to the distance between elements arranged vertically on a webpage. In CSS, it can be set between list items using properties like margin or padding etc. These properties help create a visually appealing layout, enhancing readability and organization of the content.

Below are the approaches to set vertical space between the list of items using CSS:

Table of Content

  • Using CSS line-height Property
  • Using CSS margin-top Property
  • Using CSS padding-top Property

Using CSS line-height Property

The line-height property in CSS controls the vertical spacing between lines of text or list items. By increasing the line-height value, you create more space between the lines or items.

Syntax

line-height: normal | number | length | percentage | initial | inherit;

Example: This example shows the use of the inline-height property to set vertical space between the list of items.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width,                  initial-scale=1.0">     <title>         Using line-height to         set line-height     </title>      <style>         .container {             width: 500px         }          h1 {             color: green;         }          b {             position: absolute;             top: 20%;         }          .left ul {              /* Increase line-height              compare to default */             line-height: 2.5em;             float: left;         }          .right {             float: right;         }     </style>  </head>  <body>     <div class="container">         <h1>Code World</h1>         <h4>             Using line-height property             to set line height         </h4>         <br><br>         <div class="left">             <b>line-height property effect</b><br>             <ul>                 <li>For Geeks</li>                 <li>GeeksforGeeks</li>                 <li>A Computer Science Poratal</li>             </ul>         </div>         <div class="right">             <b>No line-height property effect</b><br>             <ul>                 <li>For Geeks</li>                 <li>GeeksforGeeks</li>                 <li>A Computer Science Poratal</li>             </ul>         </div>     </div> </body>  </html> 

Output:

file

Using CSS margin-top Property

The margin-top property in CSS is used to create space above an element. It helps you control the positioning of elements on your webpage, allowing for better layout and spacing.

Note: You can also use only the CSS margin property.

Syntax

// For margin-top margin-top: length | auto | initial | inherit | percentage; // For margin-bottom margin-bottom: length | auto | initial | inherit | percentage;

Example: This example shows the use of the margin-top property to set vertical space between the list of items.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width,                  initial-scale=1.0">     <title>         Using margin-top and margin-bottom         to set line height     </title>      <style>         .container {             width: 500px         }          h1 {             color: green;         }          b {             position: absolute;             top: 20%;         }          .left {              float: left;         }          .right {              float: right;         }          li:not(:first-of-type) {             margin-top: 1.5em;         }          li:not(:last-of-type) {             margin-bottom: 1.5em;         }     </style>  </head>  <body>     <div class="container">         <h1>Code World</h1>         <h4>             Using margin-top and margin-bottom             to set line height         </h4>         <br><br>         <div class="left">             <b>margin-top property effect</b><br>             <ul>                 <li>For Geeks</li>                 <li>Geeks</li>                 <li>A Computer Science Poratal</li>             </ul>         </div>         <div class="right">             <b>margin-bottom property effect</b><br>             <ul>                 <li>For Geeks</li>                 <li>Geeks</li>                 <li>A Computer Science Poratal</li>             </ul>         </div>     </div> </body>  </html> 

Output:

Using CSS padding-top Property

The padding-top property in CSS adds space inside the top edge of an element. By applying it to list items or other elements, you increase the vertical space between items, pushing content down without affecting external element spacing.

Syntax

// For padding-top padding-top: length | initial | inherit; // For padding-bottom padding-bottom: length | initial | inherit;

Example: This example shows the use of padding-top property to set vertical space between the list of items.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width,                  initial-scale=1.0">     <title>         Using padding-top and padding-bottom         to set line height     </title>      <style>         .container {             width: 500px         }         h1 {             color: green;         }         b {             position: absolute;             top: 20%;         }         .left {              float: left;         }         .right {              float: right;         }          li:not(:first-of-type) {             padding-top: 1.0em;         }         li:not(:last-of-type) {             padding-bottom: 1.0em;         }     </style>  </head>  <body>     <div class="container">         <h1>GeeksforGeeks</h1>         <h4>             Using padding-top and padding-bottom             to set line height         </h4>         <br><br>         <div class="left">             <b>padding-top property effect</b><br>             <ul>                 <li>For Geeks</li>                 <li>GeeksforGeeks</li>                 <li>A Computer Science Poratal</li>             </ul>         </div>         <div class="right">             <b>padding-bottom property effect</b><br>             <ul>                 <li>For Geeks</li>                 <li>GeeksforGeeks</li>                 <li>A Computer Science Poratal</li>             </ul>         </div>     </div> </body>  </html> 

Output:

padding-top-bottom

Output



Next Article
How to create Vertical Menu using HTML and CSS ?
author
sanjeev2552
Improve
Article Tags :
  • CSS
  • HTML
  • Web Technologies
  • CSS-Properties
  • CSS-Questions
  • HTML-Misc

Similar Reads

  • How to prevent line breaks in the list of items using CSS?
    The display:inline-block property is used to show an element in the inline-level block container. It converts the block of elements into an inline element. Use height and width property to set an inline element. The display property is used to prevent a line break of a list of items. Syntax: element
    1 min read
  • How to Increase the Space between Dotted Border Dots using CSS?
    In CSS, increasing the space between the dots in a dotted border means adjusting the distance between each dot that makes up the border. This can be done by modifying certain CSS properties, allowing developers to control the appearance and spacing for a more customized design. Using linear-gradient
    2 min read
  • How to add lines besides a vertical text using SASS ?
    In this article, we will see how to add lines besides some vertical text using SASS. Approach: The HTML code is used to depict the basic structure of the body. Here, we define a division element with a class of wrapper to contain subsequent division elements. Another division element with a class of
    6 min read
  • How to create Vertical Menu using HTML and CSS ?
    In This article, we will learn how to create vertical menus by using HTML and CSS. Vertical Menu: We can create a vertical menu in the form of buttons and a scrollable menu. Vertical Menu is the buttons arranged in the vertical menu bar/navbar. How to create a vertical menu using buttons: We can cre
    2 min read
  • Space between two rows in a table using CSS
    The space between two rows in a table can be done using CSS border-spacing and border-collapse properties. The border-spacing property is used to set the spaces between cells of a table and border-collapse property is used to specify whether the border of the table is collapsed or not. The border-sp
    2 min read
  • How to Insert Spaces/Tabs in Text using HTML and CSS?
    When building web pages, controlling the spacing between elements and text is essential for creating visually appealing and well-structured content. HTML and CSS offer several ways to insert spaces and tabs in text. While HTML provides basic methods for adding spaces, CSS gives more control over lay
    4 min read
  • How to Vertically Align Text Next to an Image using CSS ?
    Adding images into our websites is a common practice, and there are situations where text must be vertically aligned alongside an image. For example, a user’s name should appear immediately next to their profile picture, vertically aligned for optimal readability . In this article, we will see how t
    2 min read
  • How to Add Horizontal & Vertical Space Between Elements in Tailwind CSS ?
    Tailwind CSS simplifies web design with its utility-first approach. Creating websites that look good is important in web development. Tailwind CSS is a tool that helps make this easier. One important thing to learn is how to put space between elements. Below are the approaches to Add Horizontal
    3 min read
  • How to create Vertical Navigation Bar using HTML and CSS ?
    After reading this article, you will be able to build your own vertical navigation bar. To follow this article you only need some basic understanding of HTML and CSS. Let us start writing our vertical navigation bar, first, we will write the structure of the navigation bar. In this tutorial, we crea
    3 min read
  • How to Change the Space Between Words in CSS?
    Changing the space between words in CSS enhances the readability of your text and can improve the overall aesthetics of your web pages. The word-spacing property allows you to control the spacing between words in an element. We will be going to discuss the approaches that can be used to Change the S
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences