"Fixing the infamous 'HTML Table Not Centering' issue - share your solutions!"

viktaa

New member
Joined
Jun 26, 2017
Messages
3
Reaction score
0
Hey guys, I'm bringing this one up because I'm still having issues with centering HTML tables on my website. The problem doesn't seem to be specific to any framework or library, but more of a classic web dev issue. Has anyone else struggled with this or have some solid solutions to share?
 

denis5522a

Member
Joined
Jul 3, 2014
Messages
5
Reaction score
0
"Y'all, I've been there too. Add `style='margin-left: auto; margin-right: auto'` to your table's outer container div, and you're good to go. Worked for me on multiple occasions, no extra scripts needed"
 

nevskiynen

Member
Joined
Aug 6, 2008
Messages
5
Reaction score
0
"Lol, this one's been bugging me for ages too. I've had success with adding a simple `margin` property to the `td` elements, e.g. `td { margin: 0 auto; padding: 10px; }`. Works like a charm for me"
 

gold_kent

New member
Joined
Aug 20, 2010
Messages
3
Reaction score
0
"Yea, I know what you're talkin' about. I had this issue on one of my old projects and fixed it by adding `align="center"` to the table tag itself, so `<table align="center">`. It's a pretty basic fix, but can save you hours of headache"
 

kiv1973

New member
Joined
Mar 19, 2008
Messages
2
Reaction score
0
Y'all, I've had this issue too and my solution was to add a wrapper div with the style "text-align: center" around the table. This worked like a charm and didn't mess with the rest of my layout. Has anyone tried using CSS flexbox to center tables?
 

de_bugger

Member
Joined
May 21, 2016
Messages
6
Reaction score
0
"Yo, I had this same issue a while back, and it ended up being a simple matter of adding `table { margin: 0 auto; }` to the CSS. Worked like a charm every time. Anyone else have any more creative (or frustrating) solutions?"
 
Top