176

I know there is a hr (horizontal rule) in html, but I don't believe there is a vr (vertical rule). Am I wrong and if not, why isn't there a vertical rule?

Xaisoft
  • 45,655
  • 87
  • 279
  • 432
  • 22
    This is a dead question, but with the CSS3 spec now out, you could use transform:rotate(90deg) to make a vertical, horizontal rule. – Jules Sep 02 '12 at 16:30
  • 5
    If you use flexbox as rows (display: flex; flex-direction: row;) `hr` elements will automatically become vertical. You just need to set it's `height` property (e.g. height: 80%;). – Rodrigo Aug 01 '19 at 00:09

29 Answers29

196

No, there is no vertical rule.

EDIT: It's 2021 (twelve years after I answered this question), and I no longer think my original explanation is true:

(original explanation)

It does not make logical sense to have one. HTML is parsed sequentially, meaning you lay out your HTML code from top to bottom, left to right how you want it to appear from top to bottom, left to right (generally) A vr tag does not follow that paradigm.

I'm not sure why a VR tag was never introduced, but it's likely not because of the way HTML is parsed - there are many different layout modes in HTML/CSS now that do not follow this "paradigm".

If I were to now speculate as to why there is no VR tag, I might look at MDN's definition of the HR tag as a clue:

The HTML <hr> element represents a thematic break between paragraph-level elements: for example, a change of scene in a story, or a shift of topic within a section.

In practice, however, the <hr> tag often ends up used for things other than it's semantic meaning. Although it may seem based on it's real world use that there should be a <vr> tag, it probably would not resemble anything related to the semantic definition of the <hr> tag. It was probably never thought to be introduced.

My hunch is that the creators would suggest that the domain of the solution for this problem lies in CSS, not HTML (and most of the answers to this SO question reflect that).

Nixinova's solution looks like the most elegant and modern solution to this problem.

(The rest of my old answer follows below):

This is easy to do using CSS, however. Ex:

<div style="border-left:1px solid #000;height:500px"></div>

Note that you need to specify a height or fill the container with content.

Andy Baird
  • 6,088
  • 4
  • 43
  • 63
  • 8
    Tables can separate items vertically, so what you are saying is not the real reason there is no vr tag. – CiscoIPPhone Aug 04 '09 at 10:23
  • 9
    That wasn't why tables were added to the HTML spec. Tables are for displaying tabulated data. Almost any HTML element can be used to separate items vertically (anything you set to display:block and float:left with any height set) – Andy Baird Aug 04 '09 at 17:09
  • 23
    erf. I was trying to say that if things can already be separated vertically then how would adding a vr not follow HTMLs paradigm? – CiscoIPPhone Aug 05 '09 at 09:53
  • You may want to add "padding-left: 4px" to the style (with a suitable value of course). – lhf Aug 01 '10 at 19:09
  • Is there a way to center this? – JaKXz Sep 07 '14 at 10:56
  • 4
    @CiscoIPPhone - Vertical separation would require a horizontal rule. Lateral separation would require a vertical rule. Ergo, Andy Baird is correct, I think. – Joshua Feb 23 '16 at 14:56
  • 6
    I can't agree that it doesn't follow the paradigm. As you said it is parsed sequentially, top to bottom, left to right. You can divide content that goes from left to right with a vertical rule. In earlier days of HTML I agree it would not have made logical sense. Now a vertical rule is an oft used thing in html, even though there's not a semantically correct tag for it. Just my two cents. – Hendeca May 24 '16 at 21:08
  • 3
    If you're going to split hairs and talk about which way HTML is parsed, you may want to consider that HTML is one dimensional; it reads from beginning to end. To put it another way, the only thing you need to know to edit HTML is which order the characters are in. If logical sense dictated that the browser should lay out a web page according to the direction in which the code reads, then web pages would look like a scrollable stock ticker. Fortunately, most browsers don't do that. As far as paradigm goes, I don't think HTML has had a consistent one for two or three decades. – cesoid Mar 27 '18 at 23:07
47

You can make a vertical rule like this: <hr style="width: 1px; height: 20px; display: inline-block;">

Jerska
  • 11,722
  • 4
  • 35
  • 54
matt
  • 471
  • 4
  • 2
36

An <hr> inside a display:flex will make it display vertically.

JSFiddle: https://jsfiddle.net/w6y5t1kL/

Example:

<div style="display:flex;">
  <div>
    Content
    <ul>
      <li>Continued content...</li>
    </ul>
  </div>
  <hr>
  <div>
    Content
    <ul>
      <li>Continued content...</li>
    </ul>
  </div>
</div>
Nixinova
  • 457
  • 7
  • 8
19

As pointed out by others, the concept of a vertical rule does not fit in with the original ideas behind the structure and presentation of HTML documents. However, these days (especially with the proliferation of web-apps) there are is a small number of scenarios where this would indeed be useful.

For example, consider a horizontal navigation menu fixed at the top of the screen, similar to the menu-bar in most windowed GUI applications. You have several top-level menu items arranged from left-to-right which when clicked open up drop-down menus. Years ago, it was common practice to create this with a single-row table, but this is bad HTML and it is widely recognised that the correct way to go would be a list with heavily customised CSS.

Now, say you want to group similar items, but add a vertical separator in between groups, to achieve something like this:

[Item 1a] [Item 1b] | [Item 2a] [Item 2b]

Using <hr style="width: 1px; height: 100%; ..." /> works, but may be considered semantically incorrect as you are changing what that element is actually for. Furthermore, you can't use this within certain elements where the HTML DTD allows only inline-level elements (e.g. within a <span> element).

A better option would be <span style="display: inline-block; width:1px; height:100%; background:#000; margin: 0 2px;"></span>, however not all browsers support the display: inline-block; CSS property, so the only real inline-level option is to use an image like so:

<img src="pixel.gif" alt="|" style="width:1px; height:100%; background:#000; margin: 0 2px;" />

This has the added advantage of being compatible with text-only browsers (like lynx) as the pipe character is displayed instead of the image. (It still annoys me that M$IE incorrectly uses alt text as a tooltip; that's what the title attribute is for!)

daiscog
  • 11,441
  • 6
  • 50
  • 62
8
<style type="text/css">
.vr
{
  display:inline;
  height:100%;
  width:1px;
  border:1px inset;
  margin:5px
}
</style>

<div style="font-size:50px">Vertical Rule: &rarr;<div class="vr"></div>&larr;</div>

Try it out.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
7

How about:

writing-mode:tb-rl

Where top->bottom, right->left?

We will need vertical rule for this.

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
vscpp
  • 131
  • 2
  • 2
  • That's a good point. However, it means rendering the page in an unconventional manner because you have to compete with all the other elements in the dom. Have you ever noticed that there are rendering differences between the browsers sometimes? ;) ~ Nonetheless, _very good point_. – jcolebrand Apr 14 '10 at 22:48
6

I know I am adding my answer very late, but it would be worth I am sure. You can achieve vertical line using flex and hr

See my codepen here.

Umesh
  • 2,704
  • 19
  • 21
4

Ancient question but I solved this with display:flex; and it works great:

<div style="display:flex;border:1px dotted black;margin-bottom:20px;">
    <div>
        This is a div
    </div>
    <div style="border-left:1px solid black;margin:0 7.5px;"></div>
    <div>
        This is another div
    </div>  
</div>

https://jsfiddle.net/6qfd59vm/3/

This solution also doesn't require fixed height.

Tero Heiskanen
  • 499
  • 4
  • 12
4

Try this.

You can set height and width on "div", like the scope for "hr".

The margin of "hr" is used to alignment.

<div style="display: inline-flex; width: 25px; height: 100px;">
  <hr style="margin: 0px 0px 0px 12.5px;">
</div>
Johnny
  • 41
  • 4
4

There isn't, where would it go?

Use CSS to put a border-right on an element if you want something like that.

Chad Birch
  • 73,098
  • 23
  • 151
  • 149
3

You can very easily do this by

hr{
 transform: rotate(90deg);
}
<html>
<head>
</head>
<body>
<hr>
</body> 
</html>
Be careful about the height and width of hr
Nitish
  • 31
  • 1
2

you can do in 2 way :

  1. create style as you already gave in div but change border-left to border-right
  2. take a image and make its width 1-2 px
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
2

Try it and you will know yourself:

<body>
rokon<br />
rkn <hr style="width: 1px; height: 10px; display: inline; margin-left: 2px; margin-right: 2px;" />rockon<br />
rocks
</body>
</html>
sth
  • 222,467
  • 53
  • 283
  • 367
2

HTML has little to no vertical positioning due to typographic nature of content layout. Vertical Rule just doesn't fit its semantics.

myroslav
  • 3,703
  • 23
  • 29
1

For use in HTML email for most desktop clients you have to use tables. In this case, you can use <hr> tag, with necessary (but simple) inline styling, like:

<hr width="1" size="50">

Of course that styling with CSS is more flexible, but GMail and similar don't allow using of any CSS styling other than inline...

desko
  • 23
  • 4
1

No there is not. And I will tell you a little story on why it is not. But first, quick solutions:

a) Use CSS class for basic elements span/div, e.g.: <span class="vr"></span>:

.vr{ 
   display: inline-block; 
   vertical-align: middle; 
   /* note that height must be precise, 100% does not work in some major browsers */
   height: 100px; 
   width: 1px; 
   background-color: #000;
}

Demonstration of use => https://jsfiddle.net/fe3tasa0/

b) Make a use of a one-side-only border and possibly CSS :first-child selector if you want to apply a general dividers among sibling/neigbour elements.

The story about <vr> FITTING in the original paradigm,
but still not being there:

Many answers here suggest, that vertical divider does not fit the original HTML paradigm/approach ... that is completely wrong. Also the answers contradict themselves a lot.

Those same people are probably calling their clear CSS class "clearfix" - there is nothing to fix about floating, you are just clearing it ... There was even an element in HTML3: <clear>. Sadly, this and clearance of floating is one of the few common misconceptions.

Anyway. "Back then" in the "original HTML ages", there was no thought about something like inline-block, there were just blocks, inlines and tables.

The last one is actually the reason why <vr> does not exist.
Back then it was assumed that:
If you want to verticaly divide something and/or make more blocks from left to right =>
=> you are making/want to make columns =>
=> that implies you are creating a table =>
=> tables have natural borders between their cells =>
no reason to make a <vr>

This approach is actually still valid, but as time showed, the syntax made for tables is not suitable for every case as well as it's default styles.


Another, probably later, assumption was that if you are not creating table, you are probably floating block elements. That meaning they are sticking together, and again, you can set a border, and those days probably even use the :first-child selector I suggested above...
jave.web
  • 13,880
  • 12
  • 91
  • 125
1

You can use css for simulate a vertical line, and use the class on the div

.vhLine {
  border-left: thick solid #000000;
}
1

In the context of a list item being used as navigation a <vr /> tag would be perfectly useful. The reason it does not exist is because "It does not make logical sense to have one" in the context of HTML a decade ago.

joemaddalone
  • 146
  • 2
0

You could create a custom tag as such:

<html>
<head>
<style>
vr {
display: inline-block;
// This is where you'd set the ruler color
background-color: black;
// This is where you'd set the ruler width
width: 2px;
//this is where you'd set the spacing between the ruler and surrounding text
margin: 0px 5px 0px 5px;
height: 100%;
vertical-align: top;
}
</style>
</head>
<body>
this is text <vr></vr> more text
</body>
</html>

(If anyone knows a way that I could turn this into an "open-ended" tag, like <hr> let me know and I will edit it in)

SReject
  • 3,774
  • 1
  • 25
  • 41
0

There is no tag in HTML, but you can use |.

user3576467
  • 424
  • 1
  • 7
  • 10
0

You could use the new HTML5 SVG tag:

<svg style="position:absolute;width:100%;height:100%;">
    <line id="myVerticalLine" y1="0" y2="100" x1="0" x2="0">
    </line>
</svg>
1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231
0

I find it easy to make an image of a line, and then insert it into the code as a "rule", setting the width and/or height as needed. These have all been horizontal-rule images, but there's nothing stopping me (or you) from using a "vertical-rule" image.

This is cool for many reasons; you can use different lines, colors, or patterns easily as "rules", and since they would have no text, even if you had done it the "normal" way using hr in HTML, it shouldn't impact SEO or other stuff like that. And the image file would/should be very tiny (1 or 2KB at most).

Peter Jay
  • 11
  • 1
0

Too many overly-complicated answers. Just make a TableData tag that spans how many rows you want it to using rowspan. Then use the right-border for the actual bar.

Example:

<td rowspan="5" style="border-right-color: #000000; border-right-width: thin; border-right-style: solid">&nbsp;</td>
<td rowspan="5">&nbsp;</td>

Ensure that the "&nbsp" in the second line runs the same amount of lines as the first. so that there's proper spacing between both.

This technique has served me rather well with my time in HTML5.

0

Today is possible with CSS3

hr {
  background-color:black;
  color:black;
  -webkit-transform:rotate(90deg);
  position:absolute;
  width:100px;
  height:2px;
  left:100px;
}
candlejack
  • 1,189
  • 2
  • 22
  • 51
0

For people who're trying to make columns for text, there's a column-rule property which you should consider using!

.content{
  margin: 20px 5%;
  padding: 5px;
  
}
.content p{
  -webkit-column-count: 3;
  -moz-column-count:3;
  -o-column-count:3;
  column-count: 3; 
  -webkit-column-rule: 1px solid #ccc;
  -moz-column-rule: 1px solid #ccc;
  -o-column-rule: 1px solid #ccc;
  column-rule: 1px solid #ccc;
 
  text-align: justify;
}
<div class="content">
  <p>
    Lorizzle ipsum tellivizzle sit amizzle, consectetizzle adipiscing elit. Nullam away things, shizznit stuff, suscipizzle shiz, gravida vizzle, funky fresh. Doggy phat tortizzle. Check it out its fo rizzle. Bizzle izzle shizzle my nizzle crocodizzle dapibus turpizzle tempizzle i'm in the shizzle. Mauris gizzle nibh et ghetto. Vestibulum ass phat. Pellentesque eleifend nizzle nisi. Fo shizzle my shizz shiznit fo shizzle dizzle. Donec dapibus. That's the shizzle uhuh ... yih! urna, pretium eu, mattizzle cool, shit things, nunc. Fizzle suscipizzle. Shizzlin dizzle semper daahng dawg boofron bow wow wow.



  </p>
  
  
</div>
abe312
  • 2,547
  • 25
  • 16
0
<div style="width:1px;background-color:red;height:30px;float:right;"></div>

Easily can be done using a div like this

Choxmi
  • 1,584
  • 4
  • 29
  • 47
0

HTML5 custom elements (or pure CSS)

enter image description here

1. javascript

Register your element.

var vr = document.registerElement('v-r'); // vertical rule please, yes!

*The - is mandatory in all custom elements.

2. css

v-r {
    height: 100%;
    width: 1px;
    border-left: 1px solid gray;
    /*display: inline-block;*/    
    /*margin: 0 auto;*/
}

*You might need to fiddle a bit with display:inline-block|inline because inline won't expand to containing element's height. Use the margin to center the line within a container.

3. instantiate

js: document.body.appendChild(new vr());
or
HTML: <v-r></v-r>

*Unfortunately you can't create custom self-closing tags.

usage

 <h1>THIS<v-r></v-r>WORKS</h1>

enter image description here

example: http://html5.qry.me/vertical-rule


Don't want to mess with javascript?

Simply apply this CSS class to your designated element.

css

.vr {
    height: 100%;
    width: 1px;
    border-left: 1px solid gray;
    /*display: inline-block;*/    
    /*margin: 0 auto;*/
}

*See notes above.

link to original answer on SO.

Community
  • 1
  • 1
Qwerty
  • 29,062
  • 22
  • 108
  • 136
0

The short answer is NO in pure html there is not a vr (vertical rule tag).

But since html5 allow/tolerates custom tags you can do your own working vr tag, as for example:

vr
{
    background-color: red;
    display: inline-block;
    margin: 0em 1em 0em 1em;
    height: 1em;
    width: 2px;
}
Menu item 1<vr></vr>Menu item 2<vr></vr>Menu item 3<vr></vr>Menu item 4<vr></vr>Menu item 5

Of course it is possible to use other solutions too as for instance using css to roteate by 90° a standard hr tag as indicated in other example in this page or by using any other element like a div, or a table or more or less any other element that can be styled as needed with vertical border or with background color and with height and width.

To separate menu items it is also possibile to use the pipe symbol that is: | (= u+007c) that usually can be easily found and typed directly using the computer keyboard, or the Box Drawings Light Vertical Line graphic symbol (= u+2502) (more infos: https://www.compart.com/en/unicode/U+2502).

Also, if you need to make columns as for instance into a daily newspaper, it is possible to use the following approach:

body
{
  column-count: 4;
  column-rule: 1px solid lightblue;
  text-align: justify;
}
this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper this is a very long text formated similarly to a daily newspaper 

In this last case you can style it using different css properties as:

  • column-count
  • column-gap
  • column-rule-style
  • column-rule-width
  • column-rule-color
  • column-rule
  • column-span
  • column-width

Of course not only the body can be columns styled but also div and other html elements can be styled with columns with the above approach.

In conclusion, albeit html doesn't have a vr tag on its own, it is possibile and easy to create that effect in different ways.

willy wonka
  • 1,440
  • 1
  • 18
  • 31
-2

There is not.

Why? Probably because a table with two columns will do.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
OscarRyz
  • 196,001
  • 113
  • 385
  • 569