- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a vertical line with CSS?
We can easily create a vertical line on a web page using the border-left property. The border width, style and color needs to be also set for the line to be visible on the web page.
Create a div
First, create a container for the line to appear −
<div class="vLine"></div>
Create a line
To let the line to appear, use the border-left property −
.vLine { border-left: 6px solid rgb(128, 0, 128); height: 500px; margin-left: 5%; }
Create a vertical line
To create a vertical line with CSS, the code is as follows −
<!DOCTYPE html> <html> <head> <style> .vLine { border-left: 6px solid rgb(128, 0, 128); height: 500px; margin-left: 5%; } </style> </head> <body> <h1>Vertical Line Example<h1> <div class="vLine"></div> </body> </html>
Create a centered vertical line
To center the vertical line, set the position property to absolute. With that the left property is set to 50% −
left: 50%; position: absolute;
Let us see an example to create a vertical line and center it −
<!DOCTYPE html> <html> <head> <style> .vLine { border-left: 6px solid red; height: 500px; left: 50%; position: absolute; } </style> </head> <body> <h1>Vertical Line Example<h1> <div class="vLine"></div> </body> </html>
Advertisements