<table> or <div>? Why? Why not? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grátis
+ 3

<table> or <div>? Why? Why not?

As a beginner, I find it hard to decide when to use <div> or <table>. Which one is more practical? Which one is easier to format?

14th Jul 2017, 3:30 PM
Lanie
Lanie - avatar
4 Respostas
+ 7
<< The HTML <table> element represents tabular data — that is, information expressed via a two-dimensional data table. >> source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table <table> is a semantical element, meaning that it should not be used for layout purpose, which must be handled with appropriate semantical elements related to the content, or non semantical (generic) as <div>... <div> is used as a generic block type container, for anything which doesnt have well suited existing semantical element ^^ [edit] About semantical elements: https://www.w3schools.com/html/html5_semantic_elements.asp
14th Jul 2017, 3:44 PM
visph
visph - avatar
+ 4
Tables are used when you need something like headers, rows, and columns to sort or display your data. DIV is containers that are used for most things, including containing your table. I would say most of the time you'll use a DIV, but if you think you'll need rows, columns, and headers for the columns, then use a table to display the information. As for formatting, use CSS or similar to style/format the elements. Don't use tables simply because you're wanting to use them to format certain data that's being displayed. That's something we use to do back in the 90s, and it's a horrid means of designing websites. It's the reason why we created CSS.
14th Jul 2017, 3:35 PM
AgentSmith
+ 4
<div> and <table> are not the same at all. <table> creates a board with rows and cols, while <div> is a container to organise CSS (and such) way easier. Just think of <div> as <span> but instead of inline, it's block-type.
14th Jul 2017, 3:57 PM
mexikodro thanksgiving samples 1/1
mexikodro thanksgiving samples 1/1 - avatar
+ 3
<div> and <table> are completely different by the function. <div> is used as a container of other elements, in order to manage and modify them easier. On the other hand, <table> is used to create tables (usual tables) using the other tags like <tr> <td> etc, that you are going to learn on HTML fundamentals later...
14th Jul 2017, 3:36 PM
Ledio Deda
Ledio Deda - avatar