What is the best way to minimize spacing within a table cell in an HTML table?

Looking for a solution to reduce spacing and padding in my html table cell?

#table1 td {
  font-size: 200px;
}
<table id="table1" border="1">
<tr><td>1</td></tr>
</table>

https://i.sstatic.net/kVTIu.png

Check it out at https://jsfiddle.net/3x2Lgytd/

Answer №1

The extra spacing you're noticing is caused by the way the text is formatted and also due to inherent spacing in the font glyphs. To reduce this space, you can adjust the line-height property of the text.

td {
  font-size: 200px;
  line-height: 0.8;
}
<table border="1">
  <tr>
    <td>1</td>
  </tr>
</table>

Answer №2

When you use the CSS property border-collapse: collapse; on a table element, it will collapse all borders separating the table columns...

You can also achieve the same effect by setting cell-spacing and border spacing to 0 like this:

<table cellspacing="0" style="border-spacing: 0;">

If you prefer using CSS, you can do the following:

#table1 td {
  font-size: 200px;
}

#table {
  border-collapse: collapse;
  border-spacing: 0;
}
<table id="table1" border="1" cellspacing="0">
  <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
  </tr>
  <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
  </tr>
  <tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
  </tr>
</table>

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

The child elements are stacking vertically despite implementing inline-block

I have a container with 100% width. I am trying to position three divs inside it next to each other, all with the same height as the parent. Unfortunately, despite setting the display property to inline-block, they are not aligning properly and appear sta ...

Issues with receiving incorrect orders and implementing switch case statements in JavaScript

Attempting to utilize a switch-case structure based on months. For example, if the user selects 1, it should display January. The months are stored in an array where arr[0] = January. However, when selecting 1 from the dropdown, it displays "january" inste ...

Managing a multi-page document in jQuery Mobile

Is there a way to resolve the issue of only loading the first div with the role of page from the second HTML file that is being loaded via ajax using the jQuery/jQuery Mobile framework? ...

What is the best way to have child divs occupy the entire area of the parent div while also accounting for margins

I am facing a challenge with arranging child divs inside a parent div that has a specific width. Even though I am using isotope to arrange them, the layout modes do not work well for me in terms of spacing. My goal is to have the child divs fill the space ...

Utilizing JavaScript to adjust the width of an HTML element

Struggling to manipulate the position and size of a div tag using a JavaScript function, particularly confused about how to retrieve the current width of the div. Here is the function in question function socialExt() { document.getElementById("Left") ...

Unable to conceal a div that was generated by Javascript

I have a basic HTML webpage. <!DOCTYPE html> <html lang="en> <head> <meta charset="UTF-8> <title>TEST</title> <script type="text/javascript" src="https://externalsite.com/script.js" async=true> </scri ...

UI-Select fails to display the already selected value

Does anyone have a solution for binding a UI-Select control to a Class[] list? The filling up part works fine, but I'm having trouble getting the selected item to display. Any suggestions on how to fix this? Below is my ui-select code: <ui-select ...

Challenges between Django and VSCode

As I dive into practicing website development with Django, I've encountered a problem while trying to save my work in VSCode and updating my local browser. It seems that only certain changes are being reflected. For example, when I delete code in my C ...

What steps are involved in converting .html files to .ejs format via terminal?

I'm currently working on a Node project and I have a bunch of HTML files that I need to convert to .ejs format. Does anyone know of a quick way to change all the .html files in my directory to .ejs using terminal commands? ...

Tips for displaying a modal to a user only once

I've developed a Flask application that enables multiple users to register and log in. To achieve this, I have incorporated sessions into my code. When new users land on the initial page, they are greeted with a modal introducing them to the platform. ...

How can I modify the color of JavaFX text using CSS?

Looking to jazz up my JavaFX application with some custom CSS styling. Managed to link a stylesheet to my app using the following code: //Java code FXMLLoader loader = new FXMLLoader(MainApp.class.getResource("/path/to/fxml")); Scene sce ...

Understanding JavaScript for Reading a Website's "Local Storage"

Can the local storage of one website be accessed by a different domain, or is it restricted to only the domain that saved it? ...

Updating radio button color upon selection in Boostrap

Looking to customize the colors of radio buttons found on this Bootstrap page By default, the background color is white and changes to blue when clicked. <div class="btn-group" role="group" aria-label="Basic radio toggle button ...

Having trouble displaying SVG elements in Material UI

Currently, I am faced with an issue while trying to display a .svg file in the header of a drawer using Material-UI and create-react-app. Instead of the expected .svg image, all I see is a broken image rendering. Any assistance on resolving this problem ...

Glitch in jQuery causing multiple instances of text being added to a textarea consecut

I created a response system where users can reply to comments by clicking on the reply button. Once clicked, it triggers a function that adds @user at the beginning of their comment: $('#inputField').focus(); $('#inputField').text(&apo ...

Issue regarding the carousel functioning on Bootstrap version 4.5.0

I am currently facing an issue with the carousel in the latest version of Bootstrap (4.5). I have set up a multiple item carousel by creating a grid inside it, where each item looks like this: <div class="carousel-item active"> < ...

What is the best way to include multiple font styles for different tags?

While working on a website project, the client requested to use Roboto as the main font (by Google). Different styles of Roboto such as Roboto Thin or Roboto Light were used for various elements on the page. However, I utilized the @font-face selector to e ...

Having trouble getting my local website to load the CSS stylesheet through Express and Node.js in my browser

https://i.stack.imgur.com/qpsQI.png https://i.stack.imgur.com/l3wAJ.png Here is the app.js screenshot: https://i.stack.imgur.com/l3wAJ.png I have experimented with different combinations of href and express.static(""); addresses. However, I am ...

Javascript is throwing an unexpected token error due to an HTML alteration, which is indicated by the character

Each time I make a modification to my HTML file, I encounter a javascript error saying Unexpected token '!'. It appears that any change made to the HTML file triggers a javascript error. Despite this, there is nothing incorrect with the code itse ...

Row within table extending beyond boundaries of parent div table

Is there a way to make a table row wider than its parent table? I want the button at the bottom to extend beyond the borders of the table. https://i.sstatic.net/VH0HP.png Do I need to abandon the table styling to achieve this effect? Check out this JsF ...