Versione italiana
Guida su XHTML
1. Introduzione a XHTML
XHTML è una versione più rigorosa di HTML, che segue le regole di sintassi di XML. È stato sviluppato per migliorare la compatibilità e la portabilità dei documenti web. XHTML richiede che il markup sia ben formato e che tutti gli elementi siano chiusi correttamente.
Link utili:
2. Struttura di base di un documento XHTML
Un documento XHTML ha una struttura di base simile a quella di HTML, ma con alcune differenze importanti. Ecco un esempio di un documento XHTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it"> <head> <meta charset="UTF-8" /> <title>Titolo della Pagina</title> </head> <body> <h1>Benvenuto in XHTML!</h1> <p>Questo è un paragrafo di esempio.</p> </body> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it">
<head>
<meta charset="UTF-8" />
<title>Titolo della Pagina</title>
</head>
<body>
<h1>Benvenuto in XHTML!</h1>
<p>Questo è un paragrafo di esempio.</p>
</body>
</html>
<!DOCTYPE html>
: Dichiara il tipo di documento e la versione di XHTML.xmlns
: Specifica lo spazio dei nomi XML.xml:lang
elang
: Indicano la lingua del documento.
3. Elementi XHTML comuni
Gli elementi XHTML sono simili a quelli di HTML, ma devono seguire regole più rigorose:
-
Intestazioni:
<h1>Intestazione principale</h1> <h2>Intestazione secondaria</h2>
<h1>Intestazione principale</h1> <h2>Intestazione secondaria</h2>
-
Paragrafi:
<p>Questo è un paragrafo.</p>
<p>Questo è un paragrafo.</p>
-
Link:
<a href="https://www.example.com">Visita il nostro sito</a>
<a href="https://www.example.com">Visita il nostro sito</a>
-
Immagini:
<img src="immagine.jpg" alt="Descrizione dell'immagine" />
<img src="immagine.jpg" alt="Descrizione dell'immagine" />
-
Liste:
<ul> <li>Elemento 1</li> <li>Elemento 2</li> </ul> <ol> <li>Primo elemento</li> <li>Secondo elemento</li> </ol>
<ul> <li>Elemento 1</li> <li>Elemento 2</li> </ul> <ol> <li>Primo elemento</li> <li>Secondo elemento</li> </ol>
4. Regole di sintassi di XHTML
XHTML ha alcune regole di sintassi che devono essere seguite:
-
Tutti gli elementi devono essere chiusi: Anche gli elementi vuoti devono essere chiusi con una barra (
/
).<br /> <img src="immagine.jpg" alt="Descrizione" />
<br /> <img src="immagine.jpg" alt="Descrizione" />
-
Gli attributi devono essere racchiusi tra virgolette:
<a href="https://www.example.com">Link</a>
<a href="https://www.example.com">Link</a>
-
La struttura deve essere ben formata: Ogni tag deve essere aperto e chiuso correttamente.
5. Tabelle
Le tabelle in XHTML sono create in modo simile a HTML, ma seguendo le regole di sintassi di XHTML:
<table> <tr> <th>Intestazione 1</th> <th>Intestazione 2</th> </tr> <tr> <td>Riga 1, Colonna 1</td> <td>Riga 1, Colonna 2</td> </tr> </table>
<table>
<tr>
<th>Intestazione 1</th>
<th>Intestazione 2</th>
</tr>
<tr>
<td>Riga 1, Colonna 1</td>
<td>Riga 1, Colonna 2</td>
</tr>
</table>
6. Form
I moduli in XHTML sono simili a quelli in HTML, ma devono seguire le regole di sintassi:
<form action="/submit" method="post"> <label for="name">Nome:</label> <input type="text" id="name" name="name" /> <label for="email">Email:</label> <input type="email" id="email" name="email" /> <input type="submit" value="Invia"Certo! Ecco la continuazione della guida su XHTML. ```xml <input type="submit" value="Invia" /> </form>
<form action="/submit" method="post">
<label for="name">Nome:</label>
<input type="text" id="name" name="name" />
<label for="email">Email:</label>
<input type="email" id="email" name="email" />
<input type="submit" value="Invia"Certo! Ecco la continuazione della guida su XHTML.
```xml
<input type="submit" value="Invia" />
</form>
7. Commenti in XHTML
I commenti in XHTML sono simili a quelli in HTML, ma devono essere formattati correttamente:
<!-- Questo è un commento in XHTML -->
<!-- Questo è un commento in XHTML -->
8. Utilizzo di XHTML in contesti moderni
Sebbene XHTML sia stato progettato per essere più rigoroso e strutturato rispetto a HTML, oggi HTML5 è diventato lo standard predominante per la creazione di pagine web. Tuttavia, XHTML è ancora utilizzato in alcune applicazioni e contesti, come:
- Applicazioni web che richiedono una maggiore compatibilità con XML.
- Documenti che devono essere ben formati e validi secondo le specifiche XML.
9. Risorse aggiuntive
Ecco alcune risorse utili per approfondire la tua conoscenza di XHTML:
English version
XHTML Guide
1. Introduction to XHTML
XHTML is a more rigorous version of HTML, which follows the syntax rules of XML. It was developed to improve the compatibility and portability of web documents. XHTML requires that markup be well-formed and that all elements be properly closed.
Useful links:
2. Basic structure of an XHTML document
An XHTML document has a basic structure similar to that of HTML, but with some important differences. Here is an example of an XHTML document:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta charset="UTF-8" /> <title>Page Title</title> </head> <body> <h1>Welcome to XHTML!</h1> <p>This is an example paragraph.</p> </body> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="UTF-8" />
<title>Page Title</title>
</head>
<body>
<h1>Welcome to XHTML!</h1>
<p>This is an example paragraph.</p>
</body>
</html>
<!DOCTYPE html>
: Declares the document type and XHTML version.xmlns
: Specifies the XML namespace.xml:lang
andlang
: Specifies the language of the document.
3. Common XHTML Elements
XHTML elements are similar to HTML elements, but they must follow stricter rules:
- Headings:
<h1>Main heading</h1> <h2>Subheading</h2>
<h1>Main heading</h1>
<h2>Subheading</h2>
- Paragraphs:
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
- Links:
<a href="https://www.example.com">Visit our site</a>
<a href="https://www.example.com">Visit our site</a>
- Images:
<img src="image.jpg" alt="Image description" />
<img src="image.jpg" alt="Image description" />
- Lists:
<ul> <li>Element 1</li> <li>Element 2</li> </ul> <ol> <li>First element</li> <li>Second element</li> </ol>
<ul>
<li>Element 1</li>
<li>Element 2</li>
</ul>
<ol>
<li>First element</li>
<li>Second element</li>
</ol>
4. XHTML Syntax Rules
XHTML has some syntax rules that must be followed:
- All elements must be closed: Even empty elements must be closed with a slash (
/
).
<br /> <img src="image.jpg" alt="Description" />
<br />
<img src="image.jpg" alt="Description" />
- Attributes must be enclosed in quotes:
<a href="https://www.example.com">Link</a>
<a href="https://www.example.com">Link</a>
- The structure must be well-formed: Every tag must be opened and closed properly.
5. Tables
Tables in XHTML are created similarly to HTML, but following the syntax rules of XHTML:
<table> <tr> <th>Heading 1</th> <th>Heading 2</th> </tr> <tr> <td>Row 1, Column 1</td> <td>Row 1, Column 2</td> </tr> </table>
<table>
<tr>
<th>Heading 1</th>
<th>Heading 2</th>
</tr>
<tr>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
</tr>
</table>
6. Forms
Forms in XHTML are similar to those in HTML, but must follow the syntax rules:
<form action="/submit" method="post"> <label for="name">Name:</label> <input type="text" id="name" name="name" /> <label for="email">Email:</label> <input type="email" id="email" name="email" /> <input type="submit" value="Submit" Sure! Here is the continuation of the XHTML guide. ```xml <input type="submit" value="Submit" /> </form>
<form action="/submit" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name" />
<label for="email">Email:</label>
<input type="email" id="email" name="email" />
<input type="submit" value="Submit" Sure! Here is the continuation of the XHTML guide.
```xml
<input type="submit" value="Submit" />
</form>
7. XHTML Comments
XHTML comments are similar to HTML comments, but they must be formatted correctly:
<!-- This is an XHTML comment -->
<!-- This is an XHTML comment -->
8. Using XHTML in modern contexts
Although XHTML was designed to be more rigorous and structured than HTML, HTML5 has become the predominant standard for creating web pages today. However, XHTML is still used in some applications and contexts, such as:
- Web applications that require greater compatibility with XML.
- Documents that must be well-formed and valid according to the XML specification.
9. Additional Resources
Here are some useful resources to deepen your knowledge of XHTML:
Commenti
Posta un commento