Skip to main content

Margins in CSS

Published: Asked By 2 Answers Answered

Margins in CSS are used to create create space around elements' borders. Margins applied to the top, bottom, right, and left

Share:

2 Answers

M
MUHAMMED ANAZ N Community Contributor Answered on

In CSS, margins are used to create space around elements, outside of any defined borders. Margins can be set for the top, right, bottom, and left sides of an element, and they can be specified in various units such as pixels, ems, rems, percentages, and more.

div {

margin-top: 20px;

margin-right: 10%;

margin-bottom: 20px;

margin-left: 10%;

}

S
Sooraj Community Contributor Answered on

In CSS, margins are used to create space around an element, outside of any defined borders. The CSS margin properties are used to create space around elements, outside of any defined borders. With CSS, you have full control over the margins. There are properties for setting the margin for each side of an element (top, right, bottom, and left). You can specify the margin for each side of an element using the following properties:

  • margin-top
  • margin-right
  • margin-bottom
  • margin-left

Your Answer

Other Resources

Quiz Image
Quiz

Test your knowledge with interactive quizzes.

Interview Questions Image
Interview Questions

Prepare for interviews with curated question sets.

Q&A Image
Q&A

Ask your coding-related doubts and get answers.

Certification Image
Certification

Earn certifications to enhance your resume.

internships Image
Internships

Hands-on projects to improve your skills.

Quiz Image
Quiz

Test your knowledge with interactive quizzes.

Interview Questions Image
Interview Questions

Prepare for interviews with curated question sets.

blog Image
Blogs

Add your technical blogs and read technical topics.

Certification Image
Certifications

Earn certifications to enhance your resume.