Fix Native HTML and SVG in XML Views/Fragments
This skill fixes native HTML and SVG usage in XML views/fragments that the UI5 linter detects but cannot auto-fix because they require understanding the appropriate UI5 control replacements.
Linter Rules Handled
When to Use
Apply this skill when you see linter output like:
Run npx @ui5/linter --details to get links to documentation about native HTML deprecation.
Background: Why Native HTML/SVG is Deprecated
Native HTML in XML views was supported via the sap.ui.core.HTML control and the html namespace. However, this approach:
- Bypasses UI5's control lifecycle and rendering
- Doesn't integrate with UI5 theming
- Can cause accessibility issues
- Is not compatible with modern UI5 strict mode
Fix Strategy
1. Native HTML Elements → UI5 Controls
Problem: Using HTML elements via the html: namespace.
Fix Strategy: Replace with equivalent UI5 controls.
HTML to UI5 Control Mapping
2. Complex HTML Structures
Problem: Nested HTML for layout.
Fix Strategy: Use UI5 layout controls.
3. SVG Graphics → UI5 Icons or Custom Controls
Problem: Using SVG directly in XML views.
Fix Strategy A - For Icons: Use UI5 Icon control with icon fonts.
Fix Strategy B - For Complex Graphics: Create a custom control or use HTML control.
4. Common Icon Replacements
When replacing SVG icons, use the SAP icon font:
Browse all available icons: UI5 Icon Explorer
5. HTML Content That Must Remain
For cases where HTML is absolutely required (e.g., rendering external HTML content):
Warning: Only use this for content that:
- Cannot be expressed with UI5 controls
- Has been properly sanitized
- Is from a trusted source
6. Styling Considerations
When modernizing from HTML to UI5 controls:
-
CSS Classes: Apply custom classes via the
classattribute -
Inline Styles: Use
customDatafor CSS variables or thelayoutDataaggregation -
Theming: UI5 controls automatically adapt to the selected theme (Horizon, Quartz, etc.)
Implementation Steps
-
Identify HTML/SVG usage in the linter output
-
Determine the purpose of each HTML element:
- Layout container → Use VBox, HBox, FlexBox
- Text content → Use Text, Label, Title
- Interactive elements → Use Button, Link, Input
- Images → Use Image
- Icons → Use sap.ui.core.Icon
-
Check for custom CSS that may need updating
-
Replace elements with UI5 equivalents
-
Remove the
xmlns:htmlnamespace once all HTML elements are replaced -
Test the layout to ensure visual parity
Example Fix Session
Given linter output:
Before:
After:
Notes
- UI5 controls integrate better with theming, accessibility, and responsive design
- The
html:namespace should be completely removed once modernization is done - For complex HTML (like embedded iframes), the
sap.ui.core.HTMLcontrol can be used as a last resort withsanitizeContent="true" - SVG icons should be replaced with UI5 icon font where possible for better theming support
- Consider using
sap.m.FormattedTextfor HTML-like rich text formatting - Custom controls provide the most control for complex graphical requirements
Related Skills
- fix-xml-globals: For other XML view issues like global variable access (
no-globals), ambiguous event handlers (no-ambiguous-event-handler), and legacytemplate:requiresyntax, use fix-xml-globals

