1``spaceless``
2=============
3
4.. tip::
5
6    As of Twig 1.38, use the :doc:`spaceless <../filters/spaceless>` filter instead.
7
8Use the ``spaceless`` tag to remove whitespace *between HTML tags*, not
9whitespace within HTML tags or whitespace in plain text:
10
11.. code-block:: jinja
12
13    {% spaceless %}
14        <div>
15            <strong>foo</strong>
16        </div>
17    {% endspaceless %}
18
19    {# output will be <div><strong>foo</strong></div> #}
20
21This tag is not meant to "optimize" the size of the generated HTML content but
22merely to avoid extra whitespace between HTML tags to avoid browser rendering
23quirks under some circumstances.
24
25.. tip::
26
27    If you want to optimize the size of the generated HTML content, gzip
28    compress the output instead.
29
30.. tip::
31
32    If you want to create a tag that actually removes all extra whitespace in
33    an HTML string, be warned that this is not as easy as it seems to be
34    (think of ``textarea`` or ``pre`` tags for instance). Using a third-party
35    library like Tidy is probably a better idea.
36
37.. tip::
38
39    For more information on whitespace control, read the
40    :ref:`dedicated section <templates-whitespace-control>` of the documentation and learn how
41    you can also use the whitespace control modifier on your tags.
42