Differences in line spacing can be observed between the INPUT and LABEL elements

What could be causing this unusual behavior when setting line-height to match font-size:

While the height of label is 16px, the height of input is 18px... Why is that?

If I adjust line-height: 18px or higher, the heights suddenly align. But why does this happen?

Check out the JSFiddle Example here.

<style>
label, input {

    font-size: 16px;
    line-height: 16px;
    padding: 0;
    margin: 0;
    float: left;
    border: none;            
    font-family: Arial, Helvetica, sans-serif;
}
label {
    position: absolute;
}
</style>
<form>
    <label for="email">Enter your email</label>
    <input type="email" name="email" />      
</form>

Chrome version 36 screenshots clearly display the 16/18px height contrast and absence of border, margin, or padding:

Answer ā„–1

According to the information provided on MDN's website:

For replaced inline elements such as buttons or input fields, the line-height property does not have any impact.

If you eliminate the line-height property, both elements will be rendered with a height of 18px. However, setting the line-height equal to the font-size (commonly done using a unit-less value like 1, which represents 1x the font size) can have interesting effects. For instance, by specifying a line-height of 16px, you are actually restricting the total height based on the default 18px to only 16px. This concept becomes even more apparent when setting the line-height to .5, demonstrated in this example:

input, label {
    line-height: .5;
    background: #eee;
}
input {
    background: #aaa;
}

Answer ā„–2

Have you ever wondered what exactly line-height signifies in CSS? It plays a crucial role in determining the spacing between lines within a paragraph, rather than affecting the physical height of the HTML element itself.

Just so you know, the variation in height is primarily due to the 1px border that is included in the input field but not in the label.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can multiple links be hrefed at the same time?

On my website, I have a particular anchor tag that links to another page: <li><a class="dropdown-item" href="/<%= term._id %>"><%= term.term %></a></li> Now, I am looking to add an additional href li ...

Result array, employed as an input for auto-suggest functionality

Iā€™m currently working with an array where I am iterating over an object from an API endpoint that is in stdClass format: foreach($searchResults->hits as $arr){ foreach ($arr as $obj) { $fullType = $obj->_source->categories; print_r($fu ...

Switch up the placement of the boxes by moving them in different directions, such as

I've been attempting to recreate the button movement demonstrated in this link , but I'm having trouble achieving it. Using CSS animation, I can make the buttons move in a straight line, here's what I have so far: <div id="box" style=&ap ...

Having trouble getting PHP to display an image on the webpage

When attempting to output a simple image using PHP, I noticed that it only displayed a white square. This led me to believe that the IMG file could not be found. However, when I used a basic HTML IMG tag, the file was located without any issues. Even try ...

Is there a way to convert a button into clickable text that performs the same function as the original button?

Seeking a solution to transform a button into clickable text with the same functionality. Explored resources like Google, StackOverFlow, and Youtube for answers. This is the current code snippet representing the button: <button onclick="mainApp.l ...

JavaScript - Hover function not functioning properly

Having some difficulty with the .hover() function I am fetching dribbble shots that are displayed on page load. However, I am experiencing issues when trying to add a class via hover on these shots. Interestingly, the hover functionality works perfectly ...

Maintaining the original size of the fill texture when resizing a path in SVG

I have created an SVG pattern using the following code: <svg height="10" width="10" xmlns="http://www.w3.org/2000/svg" version="1.1"> <defs> <pattern id="circles-1_4" patternUnits="userSpaceOnUse" width="10" height="10"> & ...

Which is better for cycling through a list of items: CSS or JavaScript?

Currently, I have a navigation bar set up as an unordered list (<ul>), but some list items are not visible. I want to implement functionality where clicking arrows will move the elements left or right by hiding or showing the leftmost or rightmost it ...

Maintain line breaks in the scanner input within an HTML element

Currently, I am utilizing a Zebra DS9908 scanner to scan a barcode and transfer the data onto an HTML page. However, I am encountering an issue with preserving all input characters. Despite attempting both a <div> and <textarea>, the line feed ...

How to dynamically modify a list box with JavaScript

I have an index.html file with a select tag containing multiple options for a drop-down: <label for="edu">Education</label> <select id="edu" name="edu"> <option value="0">10th</option&g ...

Slick Slider fails to load on web browsers

Hi everyone, I have a snippet of HTML code that I need help with: <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/jquery.slick/1.6.0/slick.css"/> </head> <body> ...

Creating my website with a unique inverse color scheme

I'm looking to change the color scheme of my webpage so that it is inverse (white becomes black and black becomes white) similar to the Dark Reader chrome extension: https://chrome.google.com/webstore/detail/dark-reader/eimadpbcbfnmbkopoojfekhnkhdbiee ...

Text that only occupies a portion of the screen width

My unordered list (ul) contains three list items (li). The first li element displays the text "opptakskrav" and the last li element displays "ja". Can anyone explain why the text in my second li element does not use the full width and starts a new line hal ...

Gradually vanishing words while they glide across the screen

I want to achieve a similar effect seen in the game A Dark Room. The text in the game serves two purposes which I am trying to replicate: The new text is added above the old text instead of below it, pushing the older text down the page as the game progr ...

Bootstrap is an outdated page template that lacks responsiveness

My code below features a page designed using Bootstrap HTML and CSS, but it doesn't look right on all devices. For example, on mobile devices, the grid appears zoomed in and unresponsive. I tried removing grid-template-columns: auto auto;, which fixed ...

Listening for events to wait for all XMLHttpRequest requests within an iframe

I have a basic HTML page that includes an iframe element <html> <head> $('#page-wrapper').ajaxStop(function() { console.log("Page Fully Loaded." ); }); </head> <body> <h3>Demo Page<h3> <iframe id= ...

The error message "Angular formGroup requires a FormGroup instance. Kindly provide one."

I used angular reactiveforms to create a form. The default data is successfully printed on the form, however, I am facing an error in the console that says "formGroup expects a FormGroup instance. Please pass one in." Can someone guide me on how to resolve ...

The previous method of using `vue/compiler-sfc ::v-deep` as a combinator has been phased out. Instead, opt for the new syntax `:deep(<

When developing with Nuxt 2, I am encountering numerous [@vue/compiler-sfc] ::v-deep usage as a combinator has been deprecated. Use :deep(<inner-selector>) instead. errors when running npm run dev. After attempting to resolve the issue by changing a ...

What is the best way to create a div with a smaller background color than its content?

Can someone help me with adjusting the size of a gray box in this code so that it is smaller than the text inside it? .media-body { background-color: gray; } <div class="media-body"> <h5>Lagoa Azul</h5> <span class="texto-medi ...

Designing rows and columns using Angular CSS within an ngFor loop

Is there a way to align items in a row or column based on conditions within an *ngFor loop? I want the input type to display on the next line if it is textarea, and on the same line otherwise. Check out this Stackblitz Demo for dynamically generated HTML ...