Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • 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
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App
Next Article:
HTML | DOM Style alignContent Property
Next article icon

HTML | DOM Style alignContent Property

Last Updated : 10 Aug, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

The DOM Style alignContent property is used to align the items of a flexible container when they do not use all available space on the cross-axis. 

Syntax:

  • To get the alignContent Property
object.style.alignContent
  • To set the alignContent Property
object.style.alignContent = "stretch | center | flex-start | flex-end | space-between | space-around | initial | inherit"

Property Values:

  • stretch: This is used to stretch the items to fit the container.
  • center: This is used to center the items in the container.
  • flex-start: This is used to position the items at the beginning of the container.
  • flex-end: This is used to position the items at the end of the container.
  • space-between: This is used to position the items with even space between the lines. The first item is at the first line and the last item at the last line. The other items are spaced in between.
  • space-around: This is used to position the items with equal space around them.
  • initial: This is used to set this property to its default value.
  • inherit: This inherits the property from its parent.

Return Values: It returns a string value which representing the align-content property of an element.

Example-1: Using the stretch value. 

HTML
<!DOCTYPE html> <html> <title>DOM Style alignContent property</title>  <head>     <style>         .main {             width: 250px;             height: 300px;             border: 1px solid;             display: flex;             flex-flow: row wrap;             /* setting to space-around to              observe the effect of 'stretch'*/             align-content: space-around;         }          .main div {             width: 250px;             height: 70px;             font-size: 2rem;             text-align: center;         }     </style> </head>  <body>     <h1 style="color: green">         GeeksforGeeks     </h1>     <b>DOM Style alignContent</b>       <p>Click the button to change the         value of the alignContent to "stretch"</p>       <div class="main">         <div style="background-color:green;">             Geeks         </div>         <div style="background-color:lightgreen;">             For         </div>         <div style="background-color:green;">             Geeks         </div>     </div>      <button onclick="changeAlign()">         Change alignContent     </button>      <script>         function changeAlign() {             document.querySelector('.main').style.alignContent =                 "stretch";         }      </script>  </body>  </html> 

Output:

  • Before clicking the button:

 stretch-before

  • After clicking the button:

 stretch-after

Example-2: Using the center value. 

HTML
<!DOCTYPE html> <html> <title>     DOM Style alignContent property </title>  <head>     <style>         .main {             width: 250px;             height: 300px;             border: 1px solid;             display: flex;             flex-flow: row wrap;         }          .main div {             width: 250px;             height: 70px;             font-size: 2rem;             text-align: center;         }     </style> </head>  <body>     <h1 style="color: green">         GeeksforGeeks     </h1>     <b>DOM Style alignContent</b>       <p>Click the button to change the         value of the alignContent to "center"</p>       <div class="main">         <div style="background-color:green;">             Geeks         </div>         <div style="background-color:lightgreen;">             For         </div>         <div style="background-color:green;">             Geeks         </div>     </div>      <button onclick="changeAlign()">         Change alignContent     </button>      <script>         function changeAlign() {             document.querySelector('.main').style.alignContent =                 "center";         }      </script>  </body>  </html> 

Output:

  • Before clicking the button:

 center-before

  • After clicking the button: 

center-after

Example-3: Using the flex-start value. 

HTML
<!DOCTYPE html> <html> <title>     DOM Style alignContent property </title>  <head>     <style>         .main {             width: 250px;             height: 300px;             border: 1px solid;             display: flex;             flex-flow: row wrap;         }          .main div {             width: 250px;             height: 70px;             font-size: 2rem;             text-align: center;         }     </style> </head>  <body>     <h1 style="color: green">         GeeksforGeeks     </h1>     <b>DOM Style alignContent</b>       <p>Click the button to change the         value of the alignContent to "flex-start"</p>       <div class="main">         <div style="background-color:green;">             Geeks         </div>         <div style="background-color:lightgreen;">             For         </div>         <div style="background-color:green;">             Geeks         </div>     </div>      <button onclick="changeAlign()">         Change alignContent     </button>      <script>         function changeAlign() {             document.querySelector('.main').style.alignContent =                 "flex-start";         }      </script>  </body>  </html> 

Output:

  • Before clicking the button: 

flex-start-before

  • After clicking the button:

 flex-start-after

Example-4: Using the flex-end value. 

HTML
<!DOCTYPE html> <html> <title>     DOM Style alignContent property </title>  <head>     <style>         .main {             width: 250px;             height: 300px;             border: 1px solid;             display: flex;             flex-flow: row wrap;         }          .main div {             width: 250px;             height: 70px;             font-size: 2rem;             text-align: center;         }     </style> </head>  <body>     <h1 style="color: green">         GeeksforGeeks     </h1>     <b>         DOM Style alignContent</b>       <p>Click the button to change the         value of the alignContent to "flex-end"     </p>       <div class="main">         <div style="background-color:green;">             Geeks         </div>         <div style="background-color:lightgreen;">             For         </div>         <div style="background-color:green;">             Geeks         </div>     </div>      <button onclick="changeAlign()">         Change alignContent     </button>      <script>         function changeAlign() {             document.querySelector('.main').style.alignContent =                 "flex-end";         }      </script>  </body>  </html> 

Output:

  • Before clicking the button:

 flex-end-before

  • After clicking the button:

 flex-end-after

Example-5: Using the space-between value. 

HTML
<!DOCTYPE html> <html> <title>     DOM Style alignContent property </title>  <head>     <style>         .main {             width: 250px;             height: 300px;             border: 1px solid;             display: flex;             flex-flow: row wrap;         }          .main div {             width: 250px;             height: 70px;             font-size: 2rem;             text-align: center;         }     </style> </head>  <body>     <h1 style="color: green">         GeeksforGeeks     </h1>     <b>DOM Style alignContent</b>       <p>Click the button to change the         value of the alignContent to "space-between"     </p>       <div class="main">         <div style="background-color:green;">             Geeks         </div>         <div style="background-color:lightgreen;">             For         </div>         <div style="background-color:green;">             Geeks         </div>     </div>      <button onclick="changeAlign()">         Change alignContent     </button>      <script>         function changeAlign() {             document.querySelector('.main').style.alignContent =                 "space-between";         }      </script>  </body>  </html> 

Output:

  • Before clicking the button: 

space-between-before

  • After clicking the button: 

space-between-after

Example-6: Using the space-around value. 

HTML
<!DOCTYPE html> <html> <title>     DOM Style alignContent property </title>  <head>     <style>         .main {             width: 250px;             height: 300px;             border: 1px solid;             display: flex;             flex-flow: row wrap;         }          .main div {             width: 250px;             height: 70px;             font-size: 2rem;             text-align: center;         }     </style> </head>  <body>     <h1 style="color: green">         GeeksforGeeks     </h1>     <b>DOM Style alignContent</b>       <p>Click the button to change the         value of the alignContent to "space-around"     </p>       <div class="main">         <div style="background-color:green;">             Geeks         </div>         <div style="background-color:lightgreen;">             For         </div>         <div style="background-color:green;">             Geeks         </div>     </div>      <button onclick="changeAlign()">         Change alignContent     </button>      <script>         function changeAlign() {             document.querySelector('.main').style.alignContent =                 "space-around";         }      </script>  </body>  </html> 

Output:

  • Before clicking the button: 

space-around-before

  • After clicking the button:

 space-around-after

Example-7: Using the initial value. 

HTML
<!DOCTYPE html> <html> <title>     DOM Style alignContent property </title>  <head>     <style>         .main {             width: 250px;             height: 300px;             border: 1px solid;             display: flex;             flex-flow: row wrap;             /* setting to space-around          to observe the effect of 'initial' */             align-content: space-around;         }          .main div {             width: 250px;             height: 70px;             font-size: 2rem;             text-align: center;         }     </style> </head>  <body>     <h1 style="color: green">         GeeksforGeeks     </h1>     <b>DOM Style alignContent</b>       <p>Click the button to change the         value of the alignContent to "initial"     </p>       <div class="main">         <div style="background-color:green;">             Geeks         </div>         <div style="background-color:lightgreen;">             For         </div>         <div style="background-color:green;">             Geeks         </div>     </div>      <button onclick="changeAlign()">         Change alignContent     </button>      <script>         function changeAlign() {             document.querySelector('.main').style.alignContent =                 "initial";         }      </script>  </body>  </html> 

Output:

  • Before clicking the button:

 initial-before

  • After clicking the button:

 initial-after

Example-8: Using the inherit value. 

HTML
<!DOCTYPE html> <html> <title>     DOM Style alignContent property </title>  <head>     <style>         #parent {             /* Set the align-content of          parent to observe effect of 'inherit' */             align-content: flex-end;         }          .main {             width: 250px;             height: 300px;             border: 1px solid;             display: flex;             flex-flow: row wrap;         }          .main div {             width: 250px;             height: 70px;             font-size: 2rem;             text-align: center;         }     </style> </head>  <body>     <h1 style="color: green">         GeeksforGeeks     </h1>     <b>DOM Style alignContent</b>       <p>Click the button to change the         value of the alignContent to "inherit"     </p>      <div id="parent">         <div class="main">             <div style="background-color:green;">                 Geeks             </div>             <div style="background-color:lightgreen;">                 For             </div>             <div style="background-color:green;">                 Geeks             </div>         </div>     </div>      <button onclick="changeAlign()">         Change alignContent     </button>      <script>         function changeAlign() {             document.querySelector('.main').style.alignContent =                 "inherit";         }      </script>  </body>  </html> 

Output:

  • Before clicking the button:

 inherit-before

  • After clicking the button:

 inherit-after

Supported Browsers: The browser supported by alignContent property are listed below:

  • Google Chrome 29.0 and above
  • Edge 12.0 and above
  • Internet Explorer 11.0 and above
  • Firefox 28.0 and above
  • Opera 12.1 and above
  • Safari 9.0 and above

Next Article
HTML | DOM Style alignContent Property

S

sayantanm19
Improve
Article Tags :
  • Web Technologies
  • HTML
  • HTML-DOM

Similar Reads

    HTML DOM THead align Property
    The HTML DOM THead align property is used to set or return the horizontal alignment of the content within the <thead> element. It is not supported by HTML 5. Syntax: It returns the align property. theadobject.align It sets the align property. theadObject.align = "left | right | center | justif
    2 min read
    HTML DOM TBody align Property
    The HTML DOM TBody align property is used to set or return the horizontal alignment of the content within the <tbody> element. It is not supported by HTML5. Syntax: It returns the align property. tbodyobject.align It sets the align property. tbodyObject.align = "left | right | center | justify
    2 min read
    HTML | DOM TableRow align Property
    The HTML DOM TableRow align Property is used to set or return the horizontal alignment of the content within the table row. It is not supported by HTML 5. Syntax: It returns the align property. TableRowobject.align It sets the align property. TableRowObject.align = "left | right | center | justify |
    2 min read
    HTML DOM TableData align Property
    The HTML DOM TableData align property is used to set or return the horizontal alignment of the content within the table cell. It is not supported by HTML5. Syntax: It returns the align property.TableDataobject.alignIt sets the align property.TableDataObject.align = "left | right | center | justify |
    2 min read
    HTML DOM TFoot align Property
    The HTML DOM TFoot align Property is used to set or return the horizontal alignment of the content within the <thead> element. It is not supported by HTML 5. Syntax: tfootObject.align = "left | right | center | justify | char" Property Values left: It sets the text left-align.right: It sets th
    2 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