Skip to content

BUG: to_html() contains deprecated and poorly supported HTML #39951

Open
@attack68

Description

@attack68
df = pd.DataFrame([[1,2],[3,4]], index=pd.MultiIndex.from_product([['a'], [1,2]]), columns=pd.MultiIndex.from_product([['b'], [3,4]]))
df.to_html().split('\n')

['<table border="1" class="dataframe">',
 '  <thead>',
 '    <tr>',
 '      <th></th>',
 '      <th></th>',
 '      <th colspan="2" halign="left">b</th>',
 '    </tr>',
 '    <tr>',
 '      <th></th>',
 '      <th></th>',
 '      <th>3</th>',
 '      <th>4</th>',
 '    </tr>',
 '  </thead>',
 '  <tbody>',
 '    <tr>',
 '      <th rowspan="2" valign="top">a</th>',
 '      <th>1</th>',
 '      <td>1</td>',
 '      <td>2</td>',
 '    </tr>',
 '    <tr>',
 '      <th>2</th>',
 '      <td>3</td>',
 '      <td>4</td>',
 '    </tr>',
 '  </tbody>',
 '</table>']

valign is a deprecated HTML attribute and halign is reported to be poorly supported even when it was not deprecated.
CSS solutions are recommended, but inline css like 'style="text-align:center;"' is not recommended as inline styles can break the more secure website CSPs (content security policies).

See here..
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO HTMLread_html, to_html, Styler.apply, Styler.applymap

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions